सरणी में तत्वों को संशोधित करने के लिए Select विधि का उपयोग करें।
उदाहरण
निम्न हमारी स्ट्रिंग सरणी है:
string[] stationery = { "diary", "board", "pencil", "whiteboard" };
Select विधि लैम्ब्डा अभिव्यक्ति भी निर्दिष्ट करती है:
पूर्ण कोड
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 }