
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
How to initialize a list to an empty list in C#?
To initialize a list to an empty list in C#, set it like the following statement without any elements −
List<string> list = new List<string>();
Now, use the Any() method to check whether the list is empty or not −
bool chk = !list.Any();
Let us see the complete code −
Example
using System; using System.Collections.Generic; using System.Linq; public class Program { public static void Main() { // empty list List<string> list = new List<string>(); // check for empty list bool chk = !list.Any(); if(chk) { Console.WriteLine("List is Empty!"); } else { Console.WriteLine("List isn't Empty!"); } } }
Output
List is Empty!
- Related Articles
- How to initialize an empty array list in Kotlin?
- How to initialize List in Kotlin?
- How to create an empty list in Python?
- How to initialize an empty DateTime in C#
- How to empty a C# list?
- How to initialize a dictionary to an empty dictionary in C#?
- How to initialize a string to an empty string in C#?
- How to initialize a tuple to an empty tuple in C#?
- How to declare and initialize a list in C#?
- Java Program to Initialize a List
- How to remove an empty string from a list of empty strings in C#?
- How to easily initialize a list of Tuples in C#?
- How to check if a list is empty in Python?
- How to check if a C# list is empty?
- Python - Ways to initialize list with alphabets

Advertisements