declare and assign value to variable at runtime in C#

variable names are stored in database(sql server). how can i able to declare varible with these name during runtime. after that assign value...

thanks.
amit

You could use a Dictionary<String, Object>, but unless you write some really crazy reflection you can't just instantiate a named type from the database unless that type is already named in code.

So if your database contains the String "Int32" you can use reflection to create a variable of this type. If your database contains the String "myAge", unless you have a class called "myAge" then you can't make a variable of that type, nor of that name. You'd need to use a Dictionary.

Dictionary<String, Object> myVariables = new Dictionary<String, Object>();
myVariables.Add(variableName, variableValue);

Console.WriteLine("My Variable Is: {0}", myVariables[variableName].ToString());
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.