C#Linq选择方法
使用Select方法修改数组中的元素。
以下是我们的字符串数组。
string[] stationery = { "diary", "board", "pencil", "whiteboard" };Select方法还指定Lambda表达式,如下所示-
示例
using System;
using System.Linq;
using System.Collections.Generic;
public class Demo {
public static void Main() {
string[] stationery = { "diary", "board", "pencil", "whiteboard" };
var res = stationery.AsQueryable().Select((item, index) => new { result = item.Substring(0, index + 4) });
foreach (var str in res) {
Console.WriteLine("{0}", str);
}
}
}输出结果
{ result = diar }
{ result = board }
{ result = pencil }
{ result = whitebo }热门推荐
10 朋友明天手术祝福语简短
11 14年祝福语简短情话
12 朋友搬迁新房祝福语简短
13 简短中秋祝福语朋友结婚
14 韩语贺卡祝福语简短版
15 朋友领证祝福语长文简短
16 老板生日祝福语简短语
17 新人结婚父母祝福语简短
18 毕业祝福语简短给同学