C# Enum Array Dictionary List
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp4
{
enum tagScorceLevel
{
Low=0,
Good=90
}
public class Program
{
static void Main(string[] args)
{
}
private static void DictionaryTest()
{
Dictionary<string, string> dict = new Dictionary<string, string>();
dict.Add("1","10");
dict["2"] = "20";
if (dict.TryGetValue("3",out string str))
{
Console.WriteLine("is");
}
if (dict.ContainsKey("1"))
{
string str2 = dict["1"];
Console.WriteLine(str2);
}
}
private static void ListTest()
{
string[] arr = {"cat","wolf","bird","panda"};
List<string> list = new List<string>(arr);
list.Add("pig");
list.Remove("wolf");
string[] arr2 = list.ToArray();
list.Sort((x,y)=>x.Length.CompareTo(y.Length));
List<string> list2 = list.FindAll(x=>x.Length==3);
}
public static void EnumTest()
{
int score = (int)Enum.Parse(typeof(tagScorceLevel), "Good");
Console.WriteLine(score);
if (int.TryParse(Console.ReadLine(), out int iScore))
{
tagScorceLevel level = tagScorceLevel.Low;
if (iScore >= (int)tagScorceLevel.Good)
{
level = tagScorceLevel.Good;
}
Console.WriteLine("out iScore: " + iScore);
Console.WriteLine("你得表现:" + level.ToString());
Console.ReadKey();
}
}
public static void ArrTest()
{
string animals = "Dog,cat,elephant";
string[] arr = animals.Split('\u002C');
foreach (string an in arr)
{
Console.WriteLine(an);
}
Console.ReadKey();
}
}
}