C# Program to Find the Index of Even Numbers using LINQ Last Updated : 28 Nov, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report Given an array, now our task is to find the index value of the even numbers present in the given array using LINQ. LINQ is known as Language Integrated Query and was introduced in .NET 3.5. It gives the power to .NET languages to generate queries to retrieve data from the data source. So to do this task we use the select() and where() methods of LINQ. Example: Input : { 2, 3, 4, 5, 11 } Output : Index:0 - Number: 2 Index:2 - Number: 4 Input : { 2, 3, 4, 5, 6, 23, 31 } Output : Index:0 - Number: 2 Index:2 - Number: 4 Index:4 - Number: 6Approach: 1. Create a list of integer type and add elements to it. 2. Get the index of the numbers present in the list. var indexdata = data.Select((val, indexvalue) => new { Data = val, IndexPosition = indexvalue }).Where(n => n.Data % 2 == 0).Select( result => new { Number = result.Data, IndexPosition = result.IndexPosition });3. Display the index and numbers. foreach (var i in indexdata) { Console.WriteLine("Index:" + i.IndexPosition + " - Number: " + i.Number); }Example: C# // C# program to find the index value of // the even numbers using LINQ using System; using System.Collections.Generic; using System.Linq; class GfG{ static void Main(string[] args) { // Creating a list of integer type List<int> data = new List<int>(); // Add elements to the list data.Add(2); data.Add(3); data.Add(4); data.Add(5); data.Add(6); data.Add(12); data.Add(11); // Get the index of numbers var indexdata = data.Select((val, indexvalue) => new { Data = val, IndexPosition = indexvalue }).Where(n => n.Data % 2 == 0).Select( result => new { Number = result.Data, IndexPosition = result.IndexPosition }); // Display the index and numbers // of the even numbers from the array foreach(var i in indexdata) { Console.WriteLine("Index Value:" + i.IndexPosition + " - Even Number: " + i.Number); } } } Output: Index Value:0 - Even Number: 2 Index Value:2 - Even Number: 4 Index Value:4 - Even Number: 6 Index Value:5 - Even Number: 12 Comment More infoAdvertise with us Next Article C# Program to Generate Random Even Numbers Using LINQ Parallel Query S saisravanprojects Follow Improve Article Tags : C# C# Programs Similar Reads C# Program to Find the Negative Double Numbers From the List of Objects Using LINQ Given a list of objects, we need to find the negative double from the list of objects, this task can be done using the OfType() method along with the Where() method. OfType() method is used to filter the elements of an IEnumerable based on a specified type. Or in other words, this method is used to 2 min read C# Program to Generate Random Even Numbers Using LINQ Parallel Query LINQ is known as Language Integrated Query and was introduced in .NET 3.5. It gives power to .NET languages to generate or create queries to retrieve data from the data source. In this article, we will generate random even numbers in parallel using LINQ. So, we will use ParallelQuery{TSource} to gen 2 min read How to use Array.BinarySearch() Method in C# | Set -1 Array.BinarySearch() method is used to search a value in a sorted one dimensional array. The binary search algorithm is used by this method. This algorithm searches a sorted array by repeatedly dividing the search interval in half. Begin with an interval covering the whole array. If the value of the 13 min read C# Program to Generate Odd Numbers in Parallel using LINQ LINQ is known as Language Integrated Query and it is introduced in .NET 3.5. It gives the ability to .NET languages to generate queries to retrieve data from the data source. It removes the mismatch between programming languages and databases and the syntax used to create a query is the same no matt 2 min read C# Program to Print the Numbers Greater Than 786 in an Integer Array using LINQ Language-Integrated Query (LINQ) is a uniform query syntax in C# to retrieve data from different sources. It eliminates the mismatch between programming languages and databases and also provides a single querying interface for different types of data sources. In this article, we will learn how to di 2 min read Check if a Number is Odd or Even in R Programming In R programming, it is often necessary to determine whether a given number is odd or even. An odd number is one that cannot be evenly divided by 2, whereas an even number is divisible by 2 without any remainder. This determination is useful in various scenarios, such as in decision-making processes 2 min read Like