एक सरणी सेट करें और इसे 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