Respose response = new Respose();
response.body.authentication.useraccount = "18857475598";这样赋值赋不进去,提示未将对象引用设置到对象的实例。 本人新手,求解应该怎么赋值才能赋值进去
给对象就行了
static void Main(string[] args)
{
Respose respose = new Respose();
respose.Body = new Body()
{
Authentication = new Authentication()
{
Useraccount = "aaaa"
}
};
Console.WriteLine(respose.Body.Authentication.Useraccount);
}
不这样你就一个一个new出来赋值再添加。
static void Main(string[] args)
{
Respose respose = new Respose();
Body body = new Body();
Authentication authentication = new Authentication();
authentication.Useraccount = "aaa";
body.Authentication = authentication;
respose.Body = body;
Console.WriteLine(respose.Body.Authentication.Useraccount);
}
要实例化吧,写个构造函数初始化下
应该是每个类都要实例话吧
通过反射怎么赋值啊