I have the following problem, which may seem a bit silly, but I do not give with the answer. I have the next class
public class miClase
{
public int miId {get; set;}
public string miString {get; set;}
public tipo1 miTipo1 {get; set;}
}
luego tengo otra clase tipo1
public class tipo1
{
public int idTipo1 {get; set;}
public string stTipo1 {get; set;}
}
when instantiating the type1 class, I can assign values to it in the following way
tipo1 t1 = new tipo1();
t1.idTipo1 = 1;
t1.stTipo1 = "hola";
per when instantiating the class myClass, I can not assign values to the variables of type1
miClase mc = new miClase();
mc.miId = 1; // se puede
mc.miString = "chao"; //tambien se puede
mc.tipo1.idTipo1 = 2; // me da un mensaje de null reference
mc.tipo1.stTipo1 = "esto no vale"; // supongo que tb me da el mismo error
What am I doing wrong? Can not assign values directly to the class in this way? must we necessarily instantiate a variable type1, assign values to it, and then assign it to myClass?
Greetings