“=>”是什麼東東?

 
  1. //"=>"
  2.             string[] words = { "cherry""apple""blueberry" };
  3.             //w爲words中的每個元素,w.Length()爲該元素的長度,下列代碼找出words數組中最短元素的長度
  4.             int shortestWord = words.Min(w => w.Length);
  5.             Console.WriteLine(shortestWord.ToString());
  6.             string[] digits = { "zero""one""two""three""four""five""six""seven""eight""nine" };
  7.             //digit爲digits中的每個元素,index爲該元素在digits數組中的位置(即:下標值)
  8.             //下列代碼找出digits數組中元素在digits數組中的位置小於該元素的長度的所有元素
  9.             var shortDigits = digits.Where((digit,index) => digit.Length < index);
  10.             string[] str = shortDigits.ToArray<string>();
  11.             foreach (string s in str)
  12.             {
  13.                 Console.WriteLine(s);
  14.             }
  15.             //這樣我們就可以用一個List<string[]>來創建Xmltree了
  16.             string[] xmlTreeValues = new string[] {"sky","134567890","XueFu","DaLian","LiaoNing","100623" };
  17.             List<string[]> valueList = new List<string[]>();
  18.             valueList.Add(xmlTreeValues);
  19.             XElement newContacts =
  20.                 new XElement("Contacts",
  21.                     valueList.Select(values =>
  22.                         new XElement("Contact",
  23.                             new XElement("Name", values[0]),
  24.                             new XElement("Phone", values[1]),
  25.                             new XElement("Address",
  26.                                 new XElement("Street1", values[2]),
  27.                                 new XElement("City", values[3]),
  28.                                 new XElement("State", values[4]),
  29.                                 new XElement("Postal", values[5])
  30.                             )
  31.                         )
  32.                     )
  33.                 );
  34.             Console.WriteLine(newContacts);
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章