TakeLast() পদ্ধতি ব্যবহার করে শেষ থেকে নির্দিষ্ট সংখ্যক উপাদান পান।
নিম্নলিখিত আমাদের অ্যারে.
int[] pages = { 492, 290, 129, 602, 152 }; এখন, উপাদানগুলিকে আরোহী ক্রমে অর্ডার করতে OrderBy ব্যবহার করুন। তারপর শেষ থেকে নির্দিষ্ট সংখ্যক উপাদান পেতে TakeLast() পদ্ধতি ব্যবহার করুন।
marks.AsQueryable().OrderByDescending(s => s).Take(5);
আসুন সম্পূর্ণ উদাহরণ দেখি।
উদাহরণ
using System;
using System.Linq;
using System.Collections.Generic;
public class Demo {
public static void Main() {
// pages of books
int[] pages = { 492, 290, 129, 602, 152 };
// get pages of last two books
IEnumerable<int> last = pages.AsQueryable().OrderBy(s => s).TakeLast(2);
foreach (int res in last) {
Console.WriteLine(res);
}
}
} আউটপুট
492 602