22
1
using System;
2
using System.Linq;
3
using System.Collections.Generic;
4
5
public class Program
6
{
7
public static void Main()
8
{
9
IList<int> intList = new List<int>() { 7, 10, 21, 30, 45, 50, 87 };
10
IList<string> strList = new List<string>() { null, "Two", "Three", "Four", "Five" };
11
IList<string> emptyList = new List<string>();
12
13
Console.WriteLine("1st Element in intList: {0}", intList.FirstOrDefault());
14
15
Console.WriteLine("1st Even Element in intList: {0}", intList.FirstOrDefault(i => i % 2 == 0));
16
17
Console.WriteLine("1st Element in strList: {0}", strList.FirstOrDefault());
18
19
Console.WriteLine("1st Element in emptyList: {0}", emptyList.FirstOrDefault());
20
21
}
22
}
Cached Result
System.Guid
[{"ID":"System.Guid, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089","Name":"System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"},{"ID":"305082cf-d9e7-44d4-a9bd-536de0c99436","Name":"Name1"}]
System.Guid
[{"ID":"System.Guid, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089","Name":"System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"},{"ID":"305082cf-d9e7-44d4-a9bd-536de0c99436","Name":"Name1"}]
System.Guid