সি শার্পে Where ক্লজ ব্যবহার করে কলেকশন ফিল্টার করুন। একটি একক কুয়েরি এক্সপ্রেশনে একাধিক where ক্লজ থাকতে পারে।
প্রথমে একটি কলেকশন সেট করুন −
IListemployee = new List () { new Employee() { EmpID = 1, EmpName = "Tom", EmpMarks = 90, Rank = 8} , new Employee() { EmpID = 2, EmpName = "Anne", EmpMarks = 60, Rank = 21 } , new Employee() { EmpID = 3, EmpName = "Jack", EmpMarks = 76, Rank = 18 } , new Employee() { EmpID = 4, EmpName = "Amy" , EmpMarks = 67, Rank = 20} , };
এখন, র্যাঙ্ক ৫-এর বেশি এবং ১০-এর কম থাকা কর্মচാരী পেতে একাধিক where ক্লজ ব্যবহার করুন।
var res = from e in employee where e.Rank > 5 where e.Rank < 10 select e;
কোডটি নিচে দেওয়া হলো −
উদাহরণ
using System;
using System.Linq;
using System.Collections.Generic;
public class Demo {
public static void Main() {
IList employee = new List() {
new Employee() { EmpID = 1, EmpName = "Tom", EmpMarks = 90, Rank = 8} ,
new Employee() { EmpID = 2, EmpName = "Anne", EmpMarks = 60, Rank = 21 } ,
new Employee() { EmpID = 3, EmpName = "Jack", EmpMarks = 76, Rank = 18 } ,
new Employee() { EmpID = 4, EmpName = "Amy" , EmpMarks = 67, Rank = 20} ,
};
var res = from e in employee
where e.Rank > 5
where e.Rank < 10
select e;
foreach (var emp in res) {
Console.WriteLine("নাম: " + emp.EmpName);
Console.WriteLine("মার্কস: " + emp.EmpMarks);
}
}
}
public class Employee {
public int EmpID { get; set; }
public string EmpName { get; set; }
public int EmpMarks { get; set; }
public int Rank { get; set; }
}
আউটপুট
নাম: Tom মার্কস: 90