Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# findindex

// Lets say you have an object with tha name of 'Role' nad it has parameters
// 'Name' & 'Id'

List<Role> roles = new List<Role>();
roles.Add(new Role() { Name = "Admin", Id = 1 });
roles.Add(new Role() { Name = "User", Id = 2 });

// Using a lambda expression we can find the index of a role
// with a specific text:

int roleIndex = roles.FindIndex(
	// Note that you can also use the index if youd like
	role => role.Name == "Admin"
);

// This can also be done using a variable from outside
// the lambda expression: 

string name = "Admin";
int roleIndex = roles.FindIndex(
	// Note that you can also use the index if youd like
	role => role.Name == "name
);

if (roleIndex > -1)
{
    Console.log($"Role {roles[roleIndex].Name} +
                was found at index {roleIndex}");
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: linq query get last day of month 
Csharp :: while c# 
Csharp :: c# alphabetize a list of string 
Csharp :: unity post processing on UI 
Csharp :: c# mongodb get all documents 
Csharp :: dynamic group by expression C# 
Csharp :: make variables in c# 
Csharp :: c# display image 
Csharp :: from string 
Csharp :: C# select keyword lambda 
Csharp :: c# loops 
Csharp :: export list to excel c# 
Csharp :: Write text in Word Document at specific location using C# 
Csharp :: c# sort int array 
Csharp :: All Possible SubString 
Csharp :: TimeZone in asp.net core 
Csharp :: how to store some variables on the device in unity 
Csharp :: .net core 6 autofac 
Csharp :: get number of days between two dates c# 
Csharp :: C# extract all of a property from a list of objcets 
Csharp :: element click intercepted exception in selenium C# 
Csharp :: deploy .net core 
Csharp :: check if mouse is in frame unity 
Csharp :: sum of digit of number c# 
Csharp :: how to add data in list in c# 
Csharp :: cast from object to generic type c# 
Csharp :: timer unity 
Csharp :: take photo function in unity 
Csharp :: c# const 
Csharp :: c# console delete last character 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =