Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# find item in list

MyClass result = list.Find(x => x.GetId() == "xy");
Comment

Search for a value into a list in c#

//In this example i have 2 lists with the months numbers and i will check 
//if the month have 31 or 30 days, using the method .IndexOf()
//this method search the array content and return a zero-based value,
//if found, otherwise return -1. In this example its using a List<int>
//the same process can be apllied for every list
List<int> m31 = new List<int>{ 1, 3, 5, 7, 8, 10, 12 };
List<int> m30 = new List<int>{ 4, 6, 9, 11 };

public string ValidaData(int month, int year)
{
  if (m30.IndexOf(mes) != -1)
  {
    return "have 30 days";
  }
  else if(m31.IndexOf(mes) != -1)
  {
  	return "have 30 days";
  }
  else if(mes == 2)
  {
  	if(year % 4 == 0)
      return "have 29 days";
    else
       return "have 28 days";
  }
  else
  {
  	return "Unknown month";
  }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# count directories in directory and subdirectories 
Csharp :: unity activate gameobject via script 
Csharp :: which game engine is best 
Csharp :: how set cascade on delete and update in same time in laravel 
Csharp :: c# Dictionary contains key case insensitive 
Csharp :: get enum value c# 
Csharp :: #ifdef in c 
Csharp :: c# best way to loop and remove 
Csharp :: c# arrow 
Csharp :: set text in unity invisible 
Csharp :: c# dictionary get key by value 
Csharp :: check if mouse is in frame unity 
Csharp :: c# loop through datatable and update 
Csharp :: Scrollable WPF ListBox 
Csharp :: listbox items to string c# 
Csharp :: c# method returns multiple values 
Csharp :: c# if isset 
Csharp :: c# add strings 
Csharp :: c# object list to joined string 
Csharp :: c# write line 
Csharp :: drop down list razor example 
Csharp :: unity c# find object position in array 
Csharp :: c# convertir caracter con tilde 
Csharp :: get after point in c# 
Csharp :: how to find the text position in excel in c# 
Csharp :: c# substring find word 
Csharp :: devexpress spreadsheet document source wpf 
Csharp :: convert string into float C# 
Csharp :: C# http post request with file 
Csharp :: You can get events when an object is visible within a certain camera, and when it enters or leaves, using these functions: 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =