First(), Last(), Any()

public static T First<T>(this IList<T> list) {
    return list[0];
}

public static T Last<T>(this IList<T> list) {
    return list[list.Count - 1];
}

public static bool Any<T>(this ICollection<T> list) {
    return list.Count > 0;
}
Example:
var l = new List<int> { 4, 12, 562, 1 };

Console.WriteLine(l.First()); // 4
Console.WriteLine(l.Last());  // 1
Console.WriteLine(l.Any());   // true

Description

Helper methods to simplify development. Prevent common LINQ performance mistakes.

Details

Double click on the code to select all.

 

;