- Home /
I'm using .Length() with an array but there's some problem?
Hi all,
I'm baffled by this:
childFragments.Length();
But it doesn't work! It doesn't even have .Length() as a supported function.
What gives??
Answer by Hoeloe · Sep 17, 2013 at 11:39 PM
My guess is that you're more familiar with Java than C#, judging from this mistake (not Javascript, note).
C# supports properties, while Java does not. Properties are a neat language-level way of creating getters and setters without using separate functions for each.
This allows assignments like x += 4
, where in Java, you would use: SetX(GetX()+4)
. Array Length is a read-only property in C#, and a getter method in Java. These are exactly the same semantically, but properties are implicit method calls, so do not use ().
Converted to answer because it answers the question better than the other contender, and already has more upvotes!
Answer by wiiarethesound · Sep 17, 2013 at 10:47 PM
childFragments.Length;
It's not a function, it's a variable :)
it's not a variable, it's a property (which actually is a function but used like a variable) ;)
it's totally awesome that such a simple question can provide so much entertainment value!!
ehem, 'actually' it's not a function, it's an accessor (which actually is a method ...) ;)