Accessing an instance variable by name (string), kinda like dynamic languages do, in C#
问题 i've got some C# code like this: string fieldName = ... string value = ... if (fieldName == "a") a = value; if (fieldName == "b") b = value; if (fieldName == "c") c = value; if (fieldName == "d") d = value; ... I want something like this: string fieldName = ... string value = ... SetMyInstanceVariable(fieldName, value); ... Is there a simple way to do it? I know that given a class's name in a string, you can instantiate it with System.Activator, and this is kindof similar so i was hoping....