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 9字祝福语简短创意
12 紫玫瑰生日祝福语简短
13 别人的新年祝福语简短
14 新年祝福语大全 简短情侣
15 送偶像生日祝福语简短
16 女儿生日祝福语英语简短
17 闺蜜小孩祝福语简短
18 媒人婚礼祝福语简短大气