C# Linq 选择方法
使用选择方法修改数组中的元素。
以下是我们的字符串数组。
string[] stationery = { "diary", "board", "pencil", "whiteboard" };选择方法还指定 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 }
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP