LINQ所能查詢的有陣列、XML或是 JSON.net 也支援 LINQ 查詢。
string [] names = {"Apple","Banana","Dog","Eye"}; var result = from Name in names where Name == "Apple" select Name; foreach(var Name in result){ label1.text = result; } int []score = new int[]{8,9,10,11,12,13,14}; var result = from N in score orderby s ascending where N > 10 select N; XElement xmlFile = XElement.Load("person.xml"); var student = from student in xmlFile.Elements() where (string)student.Element("id") == "1" select new { id = (string)student.Element("id"), name = (string)student.Element("name") };另外 LINQ 也可以寫擴充套件
沒有留言:
張貼留言