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
Updated on: 2020-06-22T14:05:11+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements