Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Buggz6216yIs it a List or an IEnumerable? For lazy loading reasons you need to use Count() for IEnumerables, on a List you can just access Count.
-
@Buggz I can assure you I used Count and it worked.
But that’s also an array.
I don’t understand too, must be a framework thing -
Buggz6216yWait, properties can't be made into extension methods. I don't have my laptop in front of me, so I can't check on it myself currently. Or in the near future, I don't have one right now and I ordered a new one which won't arrive until late June.
-
exelix11296yYes, count() is an extension for IEnumerable, it's not a property, it is a function defined like this:
int Count(this IEnumerable<T> Arg) {...}.
You should use Length for arrays and the Count property for Lists, for other types, trust the intellisense -
psukys2326yThis discussion is so confusing. Why isn't there a sole way of knowing amount of elements? :(
Visual Studio with C# :
list.Count
"The property Count cannot be used because the get accessor is inaccessible"
list.Count()
"You can use the Count property"
why
rant