একটি তালিকা থেকে শেষ তিনটি উপাদান প্রদর্শন করতে, Take() পদ্ধতি ব্যবহার করুন। এটিকে বিপরীত করার জন্য, বিপরীত() পদ্ধতি ব্যবহার করুন।
প্রথমত, একটি তালিকা ঘোষণা করুন এবং এতে উপাদান যোগ করুন -
List<string> myList = new List<string>();
myList.Add("One");
myList.Add("Two");
myList.Add("Three");
myList.Add("Four"); এখন, বিপরীত ক্রমে তালিকার শেষ তিনটি উপাদান প্রদর্শন করতে Reverse() এর সাথে Take() পদ্ধতি ব্যবহার করুন -
myList.Reverse<string>().Take(3);
নিচের কোড −
উদাহরণ
using System;
using System.Linq;
using System.Collections.Generic;
public class Demo {
public static void Main() {
List<string> myList = new List<string>();
myList.Add("One");
myList.Add("Two");
myList.Add("Three");
myList.Add("Four");
// first three elements
var res = myList.Reverse<string>().Take(3);
// displaying last three elements
foreach (string str in res) {
Console.WriteLine(str);
}
}
} আউটপুট
Four Three Two