let子句,可以作为临时变量储存表达式的结果,但是let子句一旦初始化后无法再次进行更改。
1.
static void Main(string[] args) { string[] names = { "xyz", "now you see", "i can say", "my abc" }; IEnumerable<string> queryFirstNames = from name in names let firstName = name.ToUpper() select firstName; foreach (string s in queryFirstNames) Console.Write(s + " "); Console.ReadLine(); }
2.
static void Main(string[] args) { string[] names = { "a 12", "b 13", "i 14", "m 15" }; var Names = from name in names let firstName = name.Split(' ') from Upper in firstName let U = Upper.ToString().ToUpper() select U; foreach (string s in Names) Console.Write(s + " "); Console.ReadLine(); }
运行结果
至此,基本语句结束。