I'm looking for mechanism in c# works like that:
Car car1;
Car car2;
Car car = (Car)SomeMechanism.Get("car1");
car1 and car2 are fields
So I want to get some object with reflection, not type :/ How can I do it in c# ?
I'm looking for mechanism in c# works like that:
Car car1;
Car car2;
Car car = (Car)SomeMechanism.Get("car1");
car1 and car2 are fields
So I want to get some object with reflection, not type :/ How can I do it in c# ?
It looks like you're trying to access local variables by reflection. This is not possible. Local variables are not accessible by reflection.
It's not possible for local variables but If you have a field, you can do
you can do
Am I correct to assume that you have two variables and that you want to get one or the other dynamically? I don't believe you can do this with reflection (at least not easily), but you can do it with functions quite easily.