Computer >> कंप्यूटर ट्यूटोरियल >  >> प्रोग्रामिंग >> C#

C# LINQ Where मेथड

Where मेथड एक सरणी के मानों को एक प्रिडिकेट के आधार पर फ़िल्टर करता है।

यहाँ, प्रिडिकेट 70 से ऊपर के तत्वों की जांच कर रहा है।

Where((n, index) => n >= 70);

उदाहरण

using System; using System.Linq; using System.Collections.Generic; public class Demo {    public static void Main() {       int[] arr = { 10, 30, 20, 15, 90, 85, 40, 75 };       Console.WriteLine("सरणी:");       foreach (int a in arr)       Console.WriteLine(a);       // 70 से ऊपर के तत्व प्राप्त करना       IEnumerable myQuery = arr.AsQueryable().Where((n, index) => n >= 70);       Console.WriteLine("70 से ऊपर के तत्व...:");       foreach (int res in myQuery)       Console.WriteLine(res);    } }

आउटपुट

सरणी: 10 30 20 15 90 85 40 75 70 से ऊपर के तत्व...: 90 85 75
  1. - C# LINQ Intersect विधि

    Intersect() विधि का उपयोग करके दो सरणियों के बीच सामान्य तत्व ढूंढें। उदाहरण निम्न हमारी सरणियाँ हैं: int[] val1 = { 15, 20, 40, 60, 75, 90 }; int[] val2 = { 17, 25, 35, 55, 75, 90 }; प्रतिच्छेदन करने के लिए: val1.AsQueryable().Intersect(val2); पूर्ण कोड using System; using System.Collections.Generi

  1. - C# LINQ में एकाधिक Where क्लॉज

    C# में Where क्लॉज का उपयोग करके संग्रह फ़िल्टर करें। एकल क्वेरी अभिव्यक्ति में एकाधिक where क्लॉज हो सकते हैं।सबसे पहले, एक संग्रह सेट करें:IList<Employee> employee = new List<Employee>() {    new Employee() { EmpID = 1, EmpName = "Tom", EmpMarks = 90, Rank = 8} , &n

  1. - C# LINQ Distinct() मेथड

    अलग-अलग तत्व प्राप्त करने के लिए, Distinct() मेथड का उपयोग करें।निम्नलिखित हमारी सूची है जिसमें डुप्लिकेट तत्व हैं।List<int> points = new List<int> { 5, 10, 5, 20, 30, 30, 40, 50, 60, 70 };अब अलग-अलग तत्व प्राप्त करने के लिए:points.AsQueryable().Distinct();आइए पूरा उदाहरण देखें:उदाहरणusi