I have the below simple declaration of nested properties (simplified):
public class standardMessage
{
public messageProperties message { get; set; }
public messageFlags flag { get; set; }
}
public class messageProperties
{
public string messageSubject { get; set; }
public string messageBody { get; set; }
}
public class messageFlags
{
public Boolean flagImportant { get; set; }
public Boolean flagPersonal { get; set; }
}
Upon initialization, I am trying to enter values, but seems I am missing something:
public class Program
{
static void Main(string[] args)
{
standardMessage myMessage = new standardMessage();
messageProperties myMsgProperties = new messageProperties();
myMsgProperties.messageSubject = "Hey!";
myMsgProperties.messageBody = "Howdy";
//below code throws error System.NullReferenceException: 'Object reference not set to an instance of an object.'
//MyMessage.message.messageSubject = "Greetings";
//MyMessage.message.messageBody = "Happy weekend";
//error - how do I print the values?
Console.WriteLine(myMessage.message.messageSubject.ToString());
Console.ReadLine();
}
}
Could you please help me with the above? wither way I tried, it doesn't run