static void Main(string[] args)
{
Console.WriteLine("---------------List泛型初体验系统定义好的-----------------------");
TestFanXing();
Console.WriteLine("---------------dictionary泛型字典系统定义好的-------------------");
FanXingDictionary();
}
/// <summary>
/// 系统自带List泛型
/// </summary>
public static void TestFanXing()
{
List<string> strList = new List<string>() { "hello", "caiqing", "fanxing" };
foreach (var item in strList)
{
Console.WriteLine(item);
}
List<int> intList = new List<int>() { 1, 5, 11, 45, 85, 78 };
foreach (var item in intList)
{
Console.WriteLine(item);
}
}
/// <summary>
/// 系统自带字典泛型
/// </summary>
public static void FanXingDictionary()
{
//泛型Dictionary<K,V> 键,值对也叫字典
Dictionary<int, string> dic = new Dictionary<int, string>();
dic.Add(1,"cai");
dic.Add(2, "qing");
//字典的遍历
foreach (var item in dic)
{
Console.WriteLine(item.Key.ToString()+" "+ item.Value);
}
//字典的查找
bool bCon = dic.ContainsValue("qing");
Console.WriteLine(bCon.ToString());
dic.Remove(1);
//字典的遍历
foreach (var item in dic)
{
Console.WriteLine(item.Key.ToString() + " " + item.Value);
}
}