FirstOrDefault 는 LINQ(Language Integrated Query)의 메서드 중 하나로, 검색을 하다가 가장 처음으로 조건에 부합하는 결과물을 도출할 때 유용합니다!
List<string> names = new List<string> { "Alice", "Bob", "Charlie", "Dave" };
string firstMatch = names.FirstOrDefault(name => name.StartsWith("B"));
Console.WriteLine(firstMatch); // Output: "Bob"
'Server > C#' 카테고리의 다른 글
[C#] out of range 에러에 대처하는 천재적인 방법 (0) | 2023.07.04 |
---|---|
[C#] ??= (0) | 2023.06.20 |
C# 델리게이트 (0) | 2023.06.09 |
[C# / JetbrainRider / Mac] NLog로 로그 남기는 법 (0) | 2023.06.02 |
static 맴버를 초기화하는 법 (정적 생성자) (0) | 2023.05.22 |