It's failing because the compiler could not find a property named Count
. Instead, it found a method—either one which isn't shown here, or if Program
implements IEnumerable<object>
, then it's likely Linq's Count
extension method.
Try adding a Count
property to Program
class Program
{
...
public int Count
{
get { return this.array.Count; }
}
}
That will solve the compiler error. Now, if you want to know why it's using indexers… well I suppose because your teacher wanted to illustrate how they can be used. Indexers are just a bit of syntactic sugar which just make writing code like p.GetItem(i)
look cleaner, p[i]
.