Dynamically Reference a Variable in Class?

How can I reference a public variable in a class NOT using dot syntax, but some way where I can use a dynamic variable name?

For example, if I have an object like this:

class DataObject{ 
	public var speed:float;
	public function DataObject(){  
		speed=55;
	}
}  

I know I can reference speed like this:

var dataObject=new DataObject();
var curSpeed=dataObject.speed;

but I want to reference it like this:

var varName="speed";
var curSpeed=dataObject[varName];

You could use a HashTable, like an array where the index can be a string. Or look into ‘eval’ on the MSDN

You could easily do what you want using reflection, but I think it would introduce a performance hit and increase the size of your executable.

I believe it's possible to override the [] operator in C# (if you must use that exact syntax) but I'm not sure.

Just out of curiosity... Why do you ask?

Is it because you're trying to translate and/or work with php code?

You can create custom indexers in C#. Details Here