string[] temArr = { "Ha", "Hunter", "Tom", "Lily", "Jay", "Jim", "Kuku", "Locu" };
List testList = new List(temArr);
if (mList.Contains("Hunter")) { Console.WriteLine("There is Hunter in the list"); }
else { mList.Add("Hunter");
Console.WriteLine("Add Hunter successfully."); }
mList.Clear();
string listFind = mList.Find( name => { if (name.Length > 3) { return true; } return false; } );
Console.WriteLine(listFind);
//name是变量,代表的是mList 中元素,自己设定
//输出是Hunter
string listFind = mList.Find( ListFind );
Console.WriteLine(listFind);
public bool ListFind(string name)
{ if (name.Length > 3) { return true; } return false; }
bool flag = mList.TrueForAll(name => { if (name.Length > 3) { return true; } else { return false; } } );
Console.WriteLine("True for all: "+flag);
//flag值为false
bool flag = mList.TrueForAll( ListFind );
Console.WriteLine("True for all: "+flag);
//flag值为false 这两种方法的结果是一样的
List subList = mList.FindAll(ListFind); //委托给ListFind函数
foreach (string s in subList) { Console.WriteLine("element in subList: "+s); }
这时subList存储的就是所有长度大于3的元素
IEnumerable takeList= mList.Take(5);
foreach (string s in takeList) { Console.WriteLine("element in takeList: " + s); }
IEnumerable whereList = mList.Where(name => { if (name.Length > 3) { return true; } else { return false; } });
foreach (string s in subList) { Console.WriteLine("element in subList: "+s); }
mList.RemoveAll( name => { if (name.Length > 3) { return true; } else { return false; } } );
foreach (string s in mList) { Console.WriteLine("element in mList: " + s); }
List> matrix = new List>();
matrix.Add(new List()); matrix[0].Add(1);
Console.WriteLine(matrix[0][0]);
Console.ReadKey();
string[] str={“1”,”2”};
List list=new List(str);
List listS=new List();
listS.Add("str");
listS.Add("hello");
System.String[] str=listS.ToArray();