c# check if list is empty
C#[Edit]
+
0
-
0
c# check if List is empty
1 2 3 4 5List<int> list = new List<int>(); bool isEmpty = !list.Any(); Console.WriteLine(isEmpty); // Output: True
[Edit]
+
0
-
0
c# check if List is empty
1 2 3 4 5List<int> list = new List<int>(); bool isEmpty = list.Count() == 0; Console.WriteLine(isEmpty); // Output: True
[Edit]
+
0
-
0
c# check if List is empty
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20using System; using System.Linq; using System.Collections.Generic; public class Program { public static void Main() { List<int> list1 = new List<int>(); List<int> list2 = new List<int> { 1, 2, 3 }; Console.WriteLine(isEmpty(list1)); // Output: True Console.WriteLine(isEmpty(list2)); // Output: False } private static bool isEmpty(List<int> list) { return !list.Any(); } }
[Edit]
+
0
-
0
c# check if List is empty
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19using System; using System.Collections.Generic; public class Program { public static void Main() { List<int> list1 = new List<int>(); List<int> list2 = new List<int> { 1, 2, 3 }; Console.WriteLine(isEmpty(list1)); // Output: True Console.WriteLine(isEmpty(list2)); // Output: False } private static bool isEmpty(List<int> list) { return list.Count == 0; } }