it works-it just wont do anything wrote:
i was trying to find out how to declare a variable using a string variable
for its name. for example if i declare\\ string a="b"; double (string a) =x
-this code actually doesn't work-\\in this case i want a double variable
named b. The whole point is that i want to be able to declare variables
without writing the code for all of them myself. thanks for any help
You are looking for something called "variable variables." PHP uses
these, and they're dangerous, and can create very odd bugs that are hard
to track down. I don't recommend thinking in that way or even using php
because it lets you think that way. Avoid variable variables. Yuck.
If you're using .NET 1.1, you can use a Hashtable:
using System.Collections;
...
Hashtable ht = new Hashtable();
ht.Add("x", 321.3);
ht.Add("y", 123.1);
// later you can access the numbers by their name:
Console.WriteLine(ht["x"]);
Console.WriteLine(ht["y"]);
If you're using .NET 2.0, you can use either a Hashtable as above (don't
forget to include that using statement above), or you can use a
Dictionary<K,V>:
using System.Collections.Generic;
...
Dictionary<string, double> d = new Dictionary<string, double>();
d.Add("x", 321.3);
d.Add("y", 123.1);
// later you can access the numbers by their name:
Console.WriteLine(d["x"]);
Console.WriteLine(d["y"]);
Hope that helps.