किसी सरणी के अंत से तत्वों को वापस करने के लिए TakeLast() विधि का उपयोग करें।
आइए पहले एक सरणी घोषित करें और आरंभ करें।
int[] prod = { 110, 290, 340, 540, 456, 698, 765, 789}; अब, अंतिम तीन तत्व प्राप्त करें।
IEnumerable<int> units = prod.AsQueryable().TakeLast(3);
आइए देखें पूरा कोड।
उदाहरण
using System;
using System.Linq;
using System.Collections.Generic;
public class Demo {
public static void Main() {
int[] prod = { 110, 290, 340, 540, 456, 698, 765, 789};
// value of last three products
IEnumerable<int> units = prod.AsQueryable().TakeLast(3);
foreach (int res in units) {
Console.WriteLine(res);
}
}
} आउटपुट
698 765 789