Null List in C#



A null list exists in C#. To check whether a list is null or not, check them against the null literal. Set a null like this −

List<string> myList = null;

Now, to check for null, use the equality operator −

myList == null;

The following is an example −

Example

 Live Demo

using System;
using System.Collections.Generic;
using System.Linq;
public class Demo {
   public static void Main() {
      List<string> myList = null;
      // checking for null
      Console.WriteLine(myList == null);
   }
}

Output

True
Samual Sam
Samual Sam

Learning faster. Every day.


Advertisements