Is it possible to convert a string value to a variable name ?

Considering the following example

AddNode(treeview, "root", "This is the root");

public void AddNode(TreeNode parent, string nodeName, string nodeValue)
        {
            // what i want to happen is here to be created node with the name "root"

            // TreeNode root = new TreeNode(nodeValue);
            // parent.Nodes.Add(root);

            // so is there a way to convert the string value of nodeName to 
            // somehow get it as a variable name

            
        }

Recommended Answers

All 3 Replies

Don't think there is. Through Reflection?
Perhaps use an if statement?

If i understand your question correctly you can use the name property of the created treenode(root.Name = nodeName) to set the name of 'root; to a string.

>convert string to a variable name

Maybe you should have to look at Dictionary<K,V>.

Dictionary<string,string> val=new Dictionary<string,string>();
 val.Add("var1","value1");
 ...
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.