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