Hello World – Reflection Style

My name is Kathy Kam and I am the newest addition to the Common Language Runtime (CLR) Program Management (PM) team. Like another PM on my team, JoelPob, I also grew up in the "Land Down Under". I left Sydney to pursue a degree in Computer Engineering and Mathematics at the University of Michigan - Ann Arbor. Upon graduation, I joined Microsoft as a developer for Microsoft Office Outlook. Four years later, after shipping Microsoft Office System 2003, a handful of Service Packs and working on Office 12 for two years, I decided to become a PM on the CLR team and here I am, writing my first post!

This blog will be a record of my insights to the .NET world. In the computing community, the first thing any developer writes is a "Hello World" program. Since this is a blog for all the computer geeks in us. Here it is, "Hello World" Reflection style:

using System;
using System.Reflection;

namespace HelloWorld
    class Program
        static void Main(string[] args)
            foreach (FieldInfo fi in typeof(HelloObj).GetFields())
                Console.Write(fi.Name + " ");

    class HelloObj
        // My output
        public string Hello;
        public int World;       
        public bool from;
        public int[] Kathy;
        public float Kam;       

The output will be:

> Hello World from Kathy Kam

Comments (12)

  1. Eric W says:

    lol. That is one of the cleverest ways I’ve seen to do "Hello World".

  2. Hi!

    Just to be the wiseguy that I am, I have to point out that your code is broken. It depends on Type.GetFields() to return the fields in a particular order, but the order is not guaranteed.

    Say hi to Joel for me πŸ™‚

  3. Hugo Batista says:

    Hi Kathy,

    The geek world welcomes you.

    BTW, do you really need the public fields ? And the lower case in "from".. hum.. And "HelloObj" ? It is an object already ? πŸ™‚ The FxCop team will ban this hello, no ?

    Just kidding πŸ™‚

  4. Mohammed says:

    Nice way to do a hello world Kathy,All the best at the CLR team

  5. Marlun says:

    Hello! =)

    Happy to see that you’ve started a blog, another one for my list and more information to gather πŸ™‚


    Marlun, Sweden

  6. KathyKam says:

    Hi Hugo,

    Yeah, I was not following the Design Guidelines. My bad. I made "from" lower case so that it spells it out like a sentence correctly. Regarding "HelloObj"… old habits die hard.



  7. Dmitry Shaporenkov says:

    Hi Kathy,

    you’re welcome. The first question that came to my mind when I was looking at your program is why ‘Kathy’ field is an array? Is there any special meaning in this?

    Sorry if I’m missing something obvious πŸ™‚



  8. Themes says:

    Kathy, aren’t you heared about new Lambda-style programming? Here is more modern way to do things πŸ˜‰

    static void Main(string[] args)


    List<FieldInfo> fields = new List<FieldInfo>(typeof(HelloObj).GetFields());

    List<string> fieldNames = fields.ConvertAll<string>(

    delegate(FieldInfo f) { return f.Name+" "; });



  9. Themes says:

    Or even shorter:

    static void Main(string[] args)


    new List<FieldInfo>(typeof(HelloObj).GetFields())

    .ConvertAll<string>(delegate(FieldInfo f) { return f.Name+" "; })



  10. SN says:

    Hi Kathy,

    Congrats on your new position. That was certainly a creative way to Hello the world.

    By the way, since you just joined the team, the interview experience must be fresh in your mind. Can you blog about your PM interview experience in the CLR team?



  11. esteewhy says:


    sorry, but how can one really get the order in which FieldInfoS are returned by Type.GetFields(), as <a href="http://blogs.msdn.com/kathykam/archive/2005/09/21/472566.aspx#474548">Jeroen Frijters</a> pointed? This is an interesting question and msdn keeps silent …

    Thank you

  12. Tadej says:

    Cool !

    Could we force the field layout by:


    class HelloObj { … }

    Or does StructLayout only have effect only when the object is actually marshaled to the unmanaged code?

Skip to main content