To align with other methods in the framework I would call it GetCountOrDefault
or possible CountOrDefault
. Similar methods from which I would look to for predecence.
Enumerable.FirstOrDefault
Enumerable.SingleOrDefault
Enumerable.LastOrDefault
Enumerable.ElementAtOrDefault
Nullable.GetValueOrDefault
Another option is to encode the ambiguity in the return type instead of the method name by having it return a int?
instead of an int
.
public static int? GetCount(this IList list) {
return list != null ? (int?)list.Count : null;
}