Take() পদ্ধতি ব্যবহার করে শুরু থেকে নির্দিষ্ট সংখ্যক উপাদান পান।
নিচে আমাদের অ্যারেটি দেওয়া হলো।
int[] marks = { 35, 72, 50, 90, 95, 85, 52, 67 };এখন, উপাদানগুলো অবরোহক্রমে সাজানোর জন্য OrderByDescending ব্যবহার করুন। তারপর উপাদানগুলো পाने Take() পদ্ধতি ব্যবহার করুন।
marks.AsQueryable().OrderByDescending(s => s).Take(5);
সম্পূর্ণ উদাহরণটি নিচে দেখুন।
উদাহরণ
using System; using System.Linq; using System.Collections.Generic; public class Demo { public static void Main() { int[] marks = { 35, 72, 50, 90, 95, 85, 52, 67 }; // শীর্ষ ৫ শিক্ষার্থীর নম্বর IEnumerable<int> selMarks = marks.AsQueryable().OrderByDescending(s => s).Take(5); foreach (int res in selMarks) { Console.WriteLine(res); } } }আউটপুট
95 90 85 72 67