How to check if a list is empty or null in C#

1 Answer

0 votes
using System;
using System.Collections.Generic;

class Program
{
    static void Main() {
        List<string> list = new List<string>();
        
        if (list == null || list.Count == 0) {
            Console.WriteLine("Empty or null");
        } else {
            Console.WriteLine("Not Empty or null");
        }
    }
}




/*
run:

Empty or null

*/

 



answered Feb 12, 2024 by avibootz
...