Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

C# Linq item index

// 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);
    }
}
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: substring in c# 
Csharp :: unity scene switch 
Csharp :: Why Duplicate "..TargetFrameworkAttribute" c# assemblies created 
Csharp :: c# caractère cacher mot de passe 
Csharp :: asp.net get most recent file in directory 
Csharp :: c# usermanager update user 
Csharp :: getelement video 
Csharp :: dinktopdf page break 
Csharp :: csharp 3d array length 
Csharp :: how to hide the title bar of window in monogame 
Csharp :: display array elemetns to text box c# 
Csharp :: how to find length of list c# 
Csharp :: c# calculate checksum of file 
Csharp :: c# invokerequired wpf 
Csharp :: GetComponent<Button().onClick 
Csharp :: request a pricipal permission 
Csharp :: c# .net core entity framework one to many 
Csharp :: unity how to make gamemanager instance 
Csharp :: c# multiplicate char 
Csharp :: how to edit .csproj file 
Csharp :: how to use open hardware monitor in c# 
Csharp :: select a whole row out of a 2d array C# 
Csharp :: How to get selected item from Dropdown in GridView 
Csharp :: list add value position c# 
Csharp :: linq select to list 
Csharp :: c# mysql select into datatable 
Csharp :: messagebox yes no c# 
Csharp :: c# sc create service 
Csharp :: asp.net web forms 
Csharp :: c# webclient vs httpclient 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =