Which method performs better: .Any() vs .Count() > 0?

If you are starting with something that has a .Length or .Count (such as ICollection<T>, IList<T>, List<T>, etc) – then this will be the fastest option, since it doesn’t need to go through the GetEnumerator()/MoveNext()/Dispose() sequence required by Any() to check for a non-empty IEnumerable<T> sequence. For just IEnumerable<T>, then Any() will generally be quicker, … Read more

What are your favorite extension methods for C#? (codeplex.com/extensionoverflow)

public static bool In<T>(this T source, params T[] list) { if(null==source) throw new ArgumentNullException(“source”); return list.Contains(source); } Allows me to replace: if(reallyLongIntegerVariableName == 1 || reallyLongIntegerVariableName == 6 || reallyLongIntegerVariableName == 9 || reallyLongIntegerVariableName == 11) { // do something…. } and if(reallyLongStringVariableName == “string1” || reallyLongStringVariableName == “string2” || reallyLongStringVariableName == “string3”) { // … Read more