1、定义一个数组string[] str= {"abcd","apple","@symjie","banana","orange"};

①查询出str中以@符号开头的

View Code
 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的元素

View Code
 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 }

 

posted on 2012-08-01 19:45  午后の時間  阅读(244)  评论(0编辑  收藏  举报