Coffeehouse Post

Single Post Permalink

View Thread: Why does C# not support this?
  • User profile image
    W3bbo

    vault said:
    Maddus Mattus said:
    *snip*

    I used to think so too, but after programming in Visual Basic properly, less is more.

     

    In C# you have

     

    MyClass myClass = new MyClass

     

    Whereas in VB you have

     

    Dim MyClass = As New MyClass

     

    which is elegant, notwithstanding the 'Dim' keyword of course - what a tragedy

     

    var myClass = new MyClass

     

    results in far less code, and is infinitely more readable in the long run, especially with long namespaces and properly formatted Linq queries. 

    That VB code fragment introduces an ambiguarity, variable "MyClass" with type "MyClass"; but I get your point.

     

    I recognise that in cases where the implementation matters as much as the interface the "traditional way" of doing things could make way for some kind of succint syntax for instantiation, how about this:

     

    SomeClass foo = new; // default constructor

    SomeClass foo = new( /* constructor params go here */ );