The List FirstOrDefault is a function that returns the first element in a list that matches a specified condition. It is a part of the System.Windows.Documents package library in C#.
Example 1:
List numbers = new List{1, 2, 3, 4, 5};
int firstEvenNumber = numbers.FirstOrDefault(n => n % 2 == 0);
Console.WriteLine(firstEvenNumber); // Outputs: 2
In this example, the List FirstOrDefault function is used to find the first even number in the given list of numbers.
Console.WriteLine(firstNameStartingWithJ); // Outputs: John
In this example, the List FirstOrDefault function is used to find the first name in the given list starting with the letter J.
Both examples use the System.Windows.Documents package library in C#.
C# (CSharp) System.Windows.Documents List.FirstOrDefault - 30 examples found. These are the top rated real world C# (CSharp) examples of System.Windows.Documents.List.FirstOrDefault extracted from open source projects. You can rate examples to help us improve the quality of examples.