Is there anyway to set a value of a static (private) variable without needing to initalize the object?
The SetValue method requires an instance, but I'm hoping there's a way to get around this.
Thanks!
Is there anyway to set a value of a static (private) variable without needing to initalize the object?
The SetValue method requires an instance, but I'm hoping there's a way to get around this.
Thanks!
For static values you can pass null for the instance parameter.
var type = typeof(SomeClass);
var field = type.GetField("SomeField");
field.SetValue(null, 42);
could you create a static function that is public and use it to set your private static variable ?