Tech Ed 2005 - Monday's Technology Highlights

C# 2.0 by Anders Hejlsberg was my favorite session today.  Here are a few points worth noting...

  • Generics
    • Can be applied at class, struct, interface, delegate, and method level
    • When applied at method level, there is no need to specify the type when using.  For example:
      // method declaration using generic
      public void MyMethod<T>(T arg) {// implementation }

      // examples of calling method explicitly
      x.MyMethod<int>(5);
      x.MyMethod<string>("Whassup");

      // examples of calling method without type (known as Type Inference)
      x.MyMethod(5);
      x.MyMethod("Whassup");
    • To set a Generic to a default initilized state use default(T)where T is the generic
    • If casting from a Generic, cast first to object, then to desired type.  For example:
      // t is a variable of a generic type
      int i = (int)(object)t;
  • Anonymous Methods
    • Here is an example of applying code directly to a click event:
      // code block is provided instead of pointing to System.Eventhandler delegate
      myButton.Click += delegate { MessageBox.Show("Muhahaha!"); };
  • Nullable Types
    • When the need arises to treat a value type as a null, here is how it can be done with C#:
      // adding the ? to the value type makes it a Nullable Type
      int? i = null;
  • Static Classes
    • Apply the static keyword to a class to enforce static only members.

 

4 Comments

  • Thanks Michael!



    Anonymous methods are kickin' ass. There is much more juicy goodness within that realm of C# 2.0 too.



    Keep the reports comin' in.

  • Yes, I liked that session too. I was sitting on the front row. Give me a call. Perhaps we're planning on attending some of the same sessions.

  • I'm not at TechEd :( I'm back here slaving away. Apparentley there's work to be done this week ;)

  • i also like that you have add access modifiers to get/set property holders. No longer does readonly have to be for the whole world.



    Example....



    private int count;

    public int Count

    {

    //Available to everyone.

    get { return count; }



    //Only available internal, effectivly

    //Readonly outside the assembly.

    internal set { count = value; }

    }

Comments have been disabled for this content.