একটি অ্যারে সেট করুন এবং OrderByDescending ব্যবহার করে এটিকে অবরোহ ক্রমে সাজান।
int[] prod = { 290, 340, 129, 540, 456, 898, 765, 789, 345}; এখন, শুরু থেকে নির্দিষ্ট সংখ্যক উপাদান ফেরত দিতে Take() পদ্ধতি ব্যবহার করুন।
Enumerable<int> units = prod.AsQueryable().OrderByDescending(s => s).Take(2);
আসুন আমরা সম্পূর্ণ কোড দেখি।
উদাহরণ
using System;
using System.Linq;
using System.Collections.Generic;
public class Demo {
public static void Main() {
int[] prod = { 290, 340, 129, 540, 456, 898, 765, 789, 345};
// Volume of top two products
IEnumerable<int> units = prod.AsQueryable().OrderByDescending(s => s).Take(2);
foreach (int res in units) {
Console.WriteLine(res);
}
}
} আউটপুট
898 789