Home > Net >  I think in the loop, obtains the corresponding name, not value, can you do it? , please people, than
I think in the loop, obtains the corresponding name, not value, can you do it? , please people, than

Time:02-21

 public string test () 
{
ImgObj a=new imgObj ();
ImgObj b=new imgObj ();
C=new imgObj imgObj ();
ImgObj [] aa={a, b, c};
String t="";

Foreach (imgObj jm in aa)
{
T +=nameof (jm)//name, namely a, b, c;

}

Return StrToJson (t);


}


I want to return as a result of the ABC not JMJMJM

CodePudding user response:

No, nameof is compiled, compiled effectively, and the operation is invalid,
A point to a new instance, and then put the instance in aa, aa has nothing to do with a
Alternatively, use a dictionary, when the add with the nameof the a to the key inside
  •  Tags:  
  • C#
  • Related