I tried to do this:
int listAverage = NumberList.Sum()/NumberList.Length;
where NumberList
is an IList
. It throws an error:
'System.Collections.Generic.IList' does not contain a definition for 'Length' and no extension method 'Length' accepting a first argument of type 'System.Collections.Generic.IList' could be found (are you missing a using directive or an assembly reference?)
That gets me thinking, why does List<T>
not have a Length
property? I know you can use Count()
instead, but Length
has an O(1) time complexity.