1、定义一个数组string[] str= {"abcd","apple","@symjie","banana","orange"};
①查询出str中以@符号开头的
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 using System; 2 using System.Linq; 3 public class Linq 4 { 5 public static void Main() 6 { 7 string[] str= {"abcd","apple","@symjie","banana","orange"}; 8 //查询出str中以@符号开头的 9 10 var result = from p in str 11 where p.StartsWith("@") 12 select p; 13 foreach(string s in result) 14 { 15 Console.WriteLine(s); 16 } 17 18 } 19 }
②查询出Str中元素长度大于5的元素
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 using System; 2 using System.Linq; 3 public class Linq 4 { 5 public static void Main() 6 { 7 string[] str= {"abcd","apple","@symjie","banana","orange"}; 8 9 10 //查询出Str中元素长度大于5的元素 11 var result1 = from p in str 12 where p.Length>5 13 select p; 14 foreach(string ss in result1) 15 { 16 Console.WriteLine(ss); 17 } 18 19 20 } 21 }