I have a struct named MyHouse for example.
struct MyHouse
{
int Light;
int Water;
int Food;
public MyHouse(int Light, int Water, int Food)
{
this.Light = Light;
this.Water = Water;
this.Food = Food;
}
}
City class:
class City
{
private MyHouse house;
public City(MyHouse house)
{
this.house = house;
}
public MyHouse GetHouse()
{
return house;
}
}
In main for example I create
City c = new City(new MyHouse(3,6,1));
where City is the class where struct MyHouse is. If I want to get the number of light from MyHouse, accessed from the City class how would I do?
MyHouseshould also be aclass.Houseis something that could be changed. It's a typical case for aclass. Most types should be classes and nothing was mentioned that suggests using astruct. MSDN: "AVOID defining a struct unless the type has all of the following characteristics: It logically represents a single value, similar to primitive types (int, double, etc.). It has an instance size under 16 bytes. It is immutable. It will not have to be boxed frequently."