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 };
// top 5 student marks
IEnumerable<int> selMarks = marks.AsQueryable().OrderByDescending(s => s).Take(5);
foreach (int res in selMarks) {
Console.WriteLine(res);
}
}
} আউটপুট
95 90 85 72 67