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("Elements..."); // প্রাথমিক লিস্ট javascript:void(0) foreach (int n in list) Console.WriteLine(n); // প্রতিটি উপাদানের ঘনফল IEnumerable<int> res = list.AsQueryable().Select(c => c * c * c); Console.WriteLine("Cube of each element..."); foreach (int n in res) Console.WriteLine(n); } }আউটপুট
Elements... 2 4 5 7 Cube of each element... 8 64 125 343