xxxxxxxxxx
List<int> numbers = new List<int>();
if (numbers.Count == 0)
{
Console.WriteLine("The list is empty.");
}
else
{
Console.WriteLine("The list is not empty.");
}
xxxxxxxxxx
if ( (myList!= null) && (!myList.Any()) )
{
// Add new item
myList.Add("new item");
}
xxxxxxxxxx
// Create an example list
List<string> myList = new List<string>();
// Check if the list is empty
if (myList.Count == 0)
{
Console.WriteLine("The list is empty.");
}
else
{
Console.WriteLine("The list is not empty.");
}