How can I use a string to access an Object variable?

Hi There, let me explain.

I have an object called "position"with a "x" variable.

If I want to access it I would use, for example:

position.x = 10; 

What I want to use on place of the "x" a string.

string anyLetter = x; 

I want to use

position[anyLetter] = 10; 

and access the variable correspondent with the letter assigned in that string, in that case "x" , how should I proceed ?

Thanks, sorry if this is super dupper easy, really beginner here.

by ZeehD via /r/csharp

Leave a Reply