Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

index in foreach c#

foreach (var item in Model.Select((value, i) => new { i, value }))
{
    var value = item.value;
    var index = item.i;
}

//or 

foreach ((MyType val, Int32 i) in Model.Select((value, i) => ( value, i )))
{
    Console.WriteLine("I am at index" + i + " and I can find the value on val");
}
Comment

foreach index start from at 1 in c#

int i = -1;
foreach (Widget w in widgets)
{
   i++;
   // do something
}
Comment

index in foreach in c#

foreach (var item in Model.Select((value, i) => new { i, value }))
{
    var value = item.value;
    var index = item.i;
}

//or 

foreach ((MyType val, Int32 i) in Model.Select((value, i) => ( value, i )))
{
    Console.WriteLine("I am at index" + i + " and I can find the value on val");
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: how to turn off sprite renderer in unity 
Csharp :: unity how to remove a tag 
Csharp :: c# convert utc to est 
Csharp :: reference to another script unity 
Csharp :: action being performed on this control is being called from the wrong thread c# 
Csharp :: list of gender binary terrorists 
Csharp :: c# datatable copy selected rows to another table 
Csharp :: c# process start 
Csharp :: c # c^b 
Csharp :: c# md5 hash file 
Csharp :: check if current time is in the morning c# 
Csharp :: uuid generator asp.net 
Csharp :: unity detect if animation is playing 
Csharp :: unity set active for seconds 
Csharp :: how to store user input into list c# 
Csharp :: unity unparent 
Csharp :: move object to mouse unity 
Csharp :: c# negative index 
Csharp :: convert int to uint c# 
Csharp :: c# string to enum 
Csharp :: stack to string c# 
Csharp :: how to move mouse in c# 
Csharp :: check distance to gameobject 
Csharp :: how to add a list to observablecollection in c# 
Csharp :: c# float to string with 2 decimals 
Csharp :: Compare trees 
Csharp :: new color unity 
Csharp :: casting string to enum type 
Csharp :: where is c# used 
Csharp :: unity normalize float 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =