C# Program to Find the Index of Even Numbers using LINQ Last Updated : 28 Nov, 2021 Comments Improve Suggest changes 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 Find the Index of Even Numbers using LINQ 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 JavaScript Program to Print Even Numbers in a Linked List A linked list is a data structure that stores the values at different memory locations concerning the next memory block of stored value. You can get all the even numbers stored in a linked list using the below methods. Table of Content Using While LoopUsing RecursionUsing While LoopTo print even num 2 min read JavaScript Program to Find Sum of Even Numbers of an Array In JavaScript, working with arrays is a basic operation. We have to sum all the even numbers present in the array. We can check the number if it is even or not by the use of the % operator. These are the following ways to find the sum of Even numbers in an Array: Table of Content Iterative ApproachU 4 min read C# Program to Find the Number Occurring Odd Number of Times Write a C# program for a given array of positive integers. All numbers occur an even number of times except one number which occurs an odd number of times. Find the number in O(n) time & constant space. Examples : Input: arr = {1, 2, 3, 2, 3, 1, 3}Output : 3 Input: arr = {5, 7, 2, 7, 5, 2, 5}Out 4 min read JavaScript Program to Check if a Number is Odd or Even We are going to learn how to check whether the number is even or Odd using JavaScript. In the number system, any natural number that can be expressed in the form of (2n + 1) is called an odd number, and if the number can be expressed in the form of 2n is called an even number.Even = {2k : k â Z}(whe 3 min read Like