Horje
c# findindex Code Example
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}");
}




Csharp

Related
solidity get address of contract Code Example solidity get address of contract Code Example
implement custom string to datetime convert net core Code Example implement custom string to datetime convert net core Code Example
hashing a file in C# Code Example hashing a file in C# Code Example
how to get the position of a camera in unity Code Example how to get the position of a camera in unity Code Example
hwo to prevent rotation after hitting an object in unity Code Example hwo to prevent rotation after hitting an object in unity Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
12