इन-ऑपरेटर का उपयोग करके एक चुनिंदा क्लॉज में क्वेरी सेट करें।
कर्मचारी विवरण के साथ हमारी सूची निम्नलिखित है -
IList<Employee> employee = new List<Employee>() { 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} , };
अब, कर्मचारी का नाम प्राप्त करें जो k के साथ समाप्त होता है और रैंक <20 और>5 ऑपरेटर का उपयोग कर रहा है।
var res = from e in employee where e.Rank > 5 where e.Rank < 20 select e into name where name.EmpName.EndsWith("k") select name;
आइए देखें पूरा कोड।
उदाहरण
using System; using System.Linq; using System.Collections.Generic; public class Demo { public static void Main() { IList<Employee> employee = new List<Employee>() { 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} , }; // fetching employee name that ends with k and rank is <20 and >5 var res = from e in employee where e.Rank > 5 where e.Rank < 20 select e into name where name.EmpName.EndsWith("k") select name; foreach (var emp in res) { Console.WriteLine("Name: "+emp.EmpName); Console.WriteLine("Marks: "+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; } }
आउटपुट
Name: Jack Marks: 76