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

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -