Is there a way to implement an Indexer on a class member and not the class itself?
This is strictly for code readability because I would like the idea of having an Indexer property of a variable within a class.
An Example would be
Then lets say I instantiate a MyClass objectCode:public class MyClass { private List<PlayerClass> player = new List<PlayerClass>(); public PlayerClass Player[int index] { get { return player[index]; } set { player.Add(value); } } }
MyClass blah = new MyClass();
I would be able to access the player list like so...
blah.Player[1]
without making the player list public. I would like to keep this member private so that I can use the properties to validate the input (even though that isn't shown in this example). I know I can do this with a method and keep my list private, I was just hoping i could use the indexer notation []. Any ideas?