2

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

Comments
  • 0
    Is 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.
  • 0
    @Buggz it was an array if I’m not wrong
  • 1
    Arrays don't have Count, use Length on those.
  • 0
    @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
  • 1
    I guess it's an extension method on LINQ if you have it in your usings?
  • 0
    @Buggz if I do have it, I didn’t know lol
  • 0
    Wait, 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.
  • 0
    Yes, 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
  • 0
    This discussion is so confusing. Why isn't there a sole way of knowing amount of elements? :(
  • 2
    @psukys Different collection types from different libraries.
Add Comment