system.reflection - C# - Can't get reflection to work in my project? -
so example of i'm trying do:
//main.cs using system; class program { static string mystring = "hello world"; }
//example.cs using system; public class dostuff { public static void showvariable() { console.writeline(this.gettype().getfield("_datafile").getvalue(this)); } } desired output:
hello world
what need do? have absolutely no idea. , yes, have looked @ questions on website reflection, don't understand it! can replace whatever pass in "_datafile" if it's variable string (such username instead of "username"), display variable?
thank you.
if got question right, want this:
public static void showvariable() { console.writeline(typeof(program).getfield("mystring", bindingflags.static | bindingflags.nonpublic).getvalue(this)); here code takes static mystring field program class.
Comments
Post a Comment