Suppose I have an array or any other collection for that matter in class and a property which returns it like following:
public class Foo
{
public IList<Bar> Bars{get;set;}
}
Now, may I write anything like this:
public Bar Bar[int index]
{
get
{
//usual null and length check on Bars omitted for calarity
return Bars[index];
}
}
Barsproperty already supports the index, so I am a bit confused about what you are trying to accomplish.Foo f=new Foo(); f.Bars[0];wow I think I should sleep now!Bars. It might be an implementation detail that should not be part ofFoos public API. Furthermore, this exposes more than the index property ofBars.Barsmay be highly stateful, and exposing it might cause a user to be able to violate the invariants thatFoopromises.