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

C# LINQ Reverse विधि

Reverse विधि का उपयोग करके सरणी में तत्वों को उल्टा करें।

उदाहरण

यहाँ हमारा वर्ण सरणी है:

char[] ch = { 't', 'i', 'm', 'e' };

अब AsQueryable() विधि के साथ Reverse() विधि का उपयोग करके उल्टा क्रम प्राप्त करें:

ch.AsQueryable().Reverse();

पूर्ण कोड

using System;
using System.Linq;
using System.Collections.Generic;

public class Demo {
    public static void Main() {
        char[] ch = { 't', 'i', 'm', 'e' };
        Console.Write("स्ट्रिंग = ");
        foreach(char arr in ch) {
            Console.Write(arr);
        }
        
        IQueryable<char> res = ch.AsQueryable().Reverse();
        Console.Write("\nउल्टी स्ट्रिंग = ");
        foreach (char c in res) {
            Console.Write(c);
        }
    }
}

आउटपुट

स्ट्रिंग = time
उल्टी स्ट्रिंग = emit
  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 मेथड

    Where मेथड एक सरणी के मानों को एक प्रिडिकेट के आधार पर फ़िल्टर करता है।यहाँ, प्रिडिकेट 70 से ऊपर के तत्वों की जांच कर रहा है।Where((n, index) => n >= 70);उदाहरणusing System; using System.Linq; using System.Collections.Generic; public class Demo {    public static void Main() {  

  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