代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string[] words = { "hello", "wonderful", "linq", "beautiful", "world" ,"csdn","qiushi07","hao"};
var shortwords = from word in words where word.Length <= 5 select word;
foreach (var word in shortwords)
Console.WriteLine(word);
Console.ReadLine();
}
}
}
执行结果如下:
先查询,然后依次打印出来。