Respose response = new Respose();
response.body.authentication.useraccount = "18857475598";这样赋值赋不进去,提示未将对象引用设置到对象的实例。 本人新手,求解应该怎么赋值才能赋值进去

C# 多层嵌套里的变量怎么赋值
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
4条回答 默认 最新
- LyphardMelody丶 2016-07-26 10:02关注
给对象就行了
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); }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 3无用