I would like to create a class with properties that have subproperties…
In other words, if I did something like:
Fruit apple = new Fruit();
I would want something like:
apple.eat(); //eats apple
MessageBox.Show(apple.color); //message box showing "red"
MessageBox.Show(apple.physicalProperties.height.ToString()); // message box saying 3
I would think it would be done like:
class Fruit{
public void eat(){
MessageBox.Show("Fruit eaten");
}
public string color = "red";
public class physicalProperties{
public int height = 3;
}
}
…but, if that were working, I wouldn’t be on here…
So close! Here’s how your code should read:
A class just defines the signature, but nested classes don’t automatically become properties.
As a side note, there’s also a couple things I’d recommend, to follow .NET’s “best practices”:
I’m sure there’s plenty of documentation on best practices too, if you’re so inclined.