[Mono-list] Reflection of non-public fields

colin at breame.net colin at breame.net
Thu Jun 29 17:56:46 EDT 2006


I'm not entirely sure I've got this right so I thought I'd run it past
"the list" before I created a bug report.

On running [1] I would expect to see "Hello World" but no output is
produced.  When I compile I see a couple of warnings about the fields
not being used - is the compiler being clever here and removing the
fields entirely?

 -- Colin

[1]:
using System;
using System.Reflection;
public class test_t {
  private string Hello;
  private string World;
  public static void Main() {
    foreach (FieldInfo fi in
             typeof(test_t).GetFields(BindingFlags.NonPublic)) {
      Console.Write("{0} ", fi.Name);
    }
    Console.WriteLine();
  }
}


More information about the Mono-list mailing list