I am getting Object reference not set to an instance of an object. exception for the following code. I can prevent this by creating an instance of RequestDetail and then passing ObjectId ot that.
But whats wrong with this code.
class Program
{
static void Main(string[] args)
{
Request header = new Request();
header.RequestDetail.ObjectId = "12343";
RequestDetail rd = new RequestDetail();
rd = header.RequestDetail;
Console.WriteLine(rd.ObjectId);
}
}
public class Request
{
public RequestDetail RequestDetail { get; set; }
}
public class RequestDetail
{
public string ObjectId { get; set; }
}
or you can initialize the RequestDetail in the Request constructor as well.