That still wont work. Lets use a baseball game for example. A baseball game would be a class and it has Innings, so those innings would be a class with seperate methods to access the top or botton of the inning, with scores, etc. Well a baseball game would have more than 1 inning, so I want to use a List<Innings> variable (keeping it private), but I want that variable to have a public indexer.... so...
BaseBallClass game = new BaseBallClass();
game.Inning[1].TopOf();
game.Innine[1].BottomOf(int runs);
game.Inning[4].BottomOf();
Code:
public class BaseBallClass
{
private List<Innings> inning = new List<Innings>();
public Innings Inning // Here I want public Innings Inning[int index] but it wont work.
{
get { return inning[index]; } // make sure its within range.
set { inning.add(value); } // use the indexer for validation purposes.
}
}
public class Innings
{
private int topInningRuns;
private int bottomInningRuns;
public int TopOf
{
//get ; set ; here
}
}
I think I am beginning to see that this can not be done unless I use public variables. Unless someone else has any ideas?