Select विधि और लैम्ब्डा अभिव्यक्ति का उपयोग करके तत्वों का घन गणना करें।
उदाहरण
निम्न हमारी सूची है:
List<int> list = new List<int> { 2, 4, 5, 7 };
अब Select() विधि का उपयोग करके घन की गणना करें:
list.AsQueryable().Select(c => c * c * c);
पूर्ण कोड
using System;
using System.Linq;
using System.Collections.Generic;
public class Demo {
public static void Main() {
List<int> list = new List<int> { 2, 4, 5, 7 };
Console.WriteLine("तत्व...");
// प्रारंभिक सूची
foreach (int n in list)
Console.WriteLine(n);
// प्रत्येक तत्व का घन
IEnumerable<int> res = list.AsQueryable().Select(c => c * c * c);
Console.WriteLine("प्रत्येक तत्व का घन...");
foreach (int n in res)
Console.WriteLine(n);
}
}
आउटपुट
तत्व... 2 4 5 7 प्रत्येक तत्व का घन... 8 64 125 343