Program.cs 855 B

12345678910111213141516171819202122232425262728
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace ConsoleLINQQuery
  7. {
  8. internal class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. //定义一个字符串数组
  13. string[] strName = new string[] { "明日科技", "C#编程词典", "C#从基础到项目实战", "C#范例手册" };
  14. //定义LINQ查询表达式,从数组中查找长度小于7的所有项
  15. IEnumerable<string> selectQuery =
  16. from Name in strName
  17. where Name.Length < 7
  18. select Name;
  19. //执行LINQ查询,并输出结果
  20. foreach (string str in selectQuery)
  21. {
  22. Console.WriteLine(str);
  23. }
  24. Console.ReadLine();
  25. }
  26. }
  27. }