Convert string to variable name

前端 未结 5 471
逝去的感伤
逝去的感伤 2020-12-20 16:53

I have an XML file, I have a node and I read all ChildNodes. The name of the childNode match to a variable I have to set with the value of this childNode.

In the loo

5条回答
  •  礼貌的吻别
    2020-12-20 17:19

    You could either do as "Default" said, or you could look into Reflection. By using the Type.GetMember(string) method you could find a member with the given name (the tag name in your XML) and set its value.

    EDIT
    Samich beat me, so I'll give him +1 - he's got sample code as well.

提交回复
热议问题