Convert string to variable name

前端 未结 5 480
逝去的感伤
逝去的感伤 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:25

    If you put the names and values in a dictionary, you can easily get the values by name:

    Dictionary parameters =
      xmlParamInstallation.SelectNodes("parameters")[0].ChildNodes
      .ToDictionary(n => n.Name, n => n.InnerText);
    
    myvar1 = parameters["myvar1"];
    myvar2 = parameters["myvar2"];
    

提交回复
热议问题