Monday, January 31, 2011

.NET/C# 5 wish list

  1. Merge WPF and Silverlight. .NET Framework and .NET Compact Framework. It would be better to have just different profiles of framework like (.NET client profile) instead of different frameworks.
  2. Non-nullable references
    string! x = "xxx";
    
  3. Discriminated unions:
    union MyUnion: Enum
    {
        case Enum.Red: RedClass;
        case Enum.Green: GreenClass;
        ...
    }
    
  4. INumeric interface for standard numeric types.
    struct UInt32: INumeric<UInt32>
    {
    ...
    }
    
  5. Fixed size arrays
    byte[10] x;
    
  6. Operator extensions (syntax sugar):
    public static class Extensions
    {
        public static T operator+ <T>(T a, T b) where T: INumeric<T>
        ...
    }
    
  7. Polymorphic up cast:
    class A: B { ... }
    ...
    new A() up B
    
    Update: No needs any more. Solution:
    public static class Extension
    {
        public static T UpCast<T>(T derived)
        {
            return derived;
        }
    }
    
    Example:
    new B().UpCast<A>()
    
  8. Force use 'using' keyword for some classes.
    using class My: IDisposable
    {
        ....
    }
    
    ...
    
    // Ok.
    using(var my = new My())
    {
    }
    
    // Compilation error.
    {
     var my = new My();
    }
    
    // Ok.
    return new My();
    
  9. Units of measurements. As in F# http://msdn.microsoft.com/en-us/library/dd233243.aspx.
  10. Named code blocks.
    code Block
    {
      foreach(var x in M)
      {
        foreach(var y in x)
        {
          if(y)
            break Block; 
        }
      }
    }
    
  11. A reference to an anonymous delegate inside the delegate.
    Control.Selected += (s, e) =>
    {
        ...
        Control.Selected -= this function;
    }
    

2 comments: