using System.Collections.Generic;
public static void Main()
IList<string> emptyList = new List<string>();
IList<int> emptyIntList = new List<int>();
IList<Student> emptyStudentList = new List<Student>();
var newList1 = emptyList.DefaultIfEmpty();
var newList2 = emptyList.DefaultIfEmpty("None");
var newList3 = emptyIntList.DefaultIfEmpty(100);
var newStudentList1 = emptyStudentList.DefaultIfEmpty();
var newStudentList2 = emptyStudentList.DefaultIfEmpty(new Student() {StudentID = 0, StudentName = "" });
Console.WriteLine("Count: {0}", newList1.Count());
Console.WriteLine("Value: {0}", newList1.ElementAt(0));
Console.WriteLine("Count: {0}", newList2.Count());
Console.WriteLine("Value: {0}", newList2.ElementAt(0));
Console.WriteLine("Count: {0}", newList3.Count());
Console.WriteLine("Value: {0}", newList3.ElementAt(0));
Console.WriteLine("Count: {0}", newStudentList1.Count());
Console.WriteLine("Student ID: {0}", newStudentList1.ElementAt(0));
Console.WriteLine("Count: {0}", newStudentList2.Count());
Console.WriteLine("Student ID: {0}", newStudentList2.ElementAt(0).StudentID);
public int StudentID { get; set; }
public string StudentName { get; set; }