- //"=>"
- string[] words = { "cherry", "apple", "blueberry" };
- //w为words中的每个元素,w.Length()为该元素的长度,下列代码找出words数组中最短元素的长度
- int shortestWord = words.Min(w => w.Length);
- Console.WriteLine(shortestWord.ToString());
- string[] digits = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };
- //digit为digits中的每个元素,index为该元素在digits数组中的位置(即:下标值)
- //下列代码找出digits数组中元素在digits数组中的位置小于该元素的长度的所有元素
- var shortDigits = digits.Where((digit,index) => digit.Length < index);
- string[] str = shortDigits.ToArray<string>();
- foreach (string s in str)
- {
- Console.WriteLine(s);
- }
- //这样我们就可以用一个List<string[]>来创建Xmltree了
- string[] xmlTreeValues = new string[] {"sky","134567890","XueFu","DaLian","LiaoNing","100623" };
- List<string[]> valueList = new List<string[]>();
- valueList.Add(xmlTreeValues);
- XElement newContacts =
- new XElement("Contacts",
- valueList.Select(values =>
- new XElement("Contact",
- new XElement("Name", values[0]),
- new XElement("Phone", values[1]),
- new XElement("Address",
- new XElement("Street1", values[2]),
- new XElement("City", values[3]),
- new XElement("State", values[4]),
- new XElement("Postal", values[5])
- )
- )
- )
- );
- Console.WriteLine(newContacts);