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