You can read all the C# performance tips from the following links,
- C# Programming Performance Tips - Part One - String Split
- C# Programming Performance Tips - Part Two - String Equals
- C# Programming Performance Tips - Part Three - Adding Strings
- C# Programming Performance Tips - Part Four - List.Count() Vs List.Any()
- C# Programming Performance Tips - Part Five - List.Count() Vs List.Count
- C# Programming Performance Tips - Part Six - Array Length
Many times, developers use List.Count() to check whether a list has data or is empty, before iterating. Here, we will compare the execution time of List.Count() and List.Any().
- Stopwatch watch = new Stopwatch();
- List < string > strs = new List < string > () {
- "Akshay",
- "Patel",
- "Panth",
- "Patel"
- };
- watch.Start();
- if (strs.Count() > 0) {}
- Console.WriteLine("List.Count()-{0}", watch.Elapsed);
- watch.Restart();
- if (strs.Any()) {}
- Console.WriteLine("List.Any() - {0}", watch.Elapsed);

The result suggests that we should use List.Any() over List.Count() wherever possible.

Jaimin ShethiyaPosted May 16, 2019, 2:07 AM
@Akshay if you have store data in List then we can directly use listName.Count. I am checked in my machine then it will take a time List.Count: 00:00:00.0000069, List.Count(): 00:00:00.0000335 and List.Any(): 00:00:00.0000470
Rajesh PatelPosted May 16, 2019, 12:46 AM
Good one akki, we should always use .Any() method to test whether collection(IEnumerbale) is empty or not. The main difference is efficiency of the operation.