Motley Motley

Niner since 2005


  • Paul Vick and Amanda Silver - VB Language Futures

    I agree Alex, the syntax:
    Dim cust as New Customer = { .Name="Me", .Address="123 Main" }

    makes more sense than
    Dim cust as Customer = { .Name="Me", .Address="123 Main" }

    Because the statement is creating an instance of the customer object, and then assigning property values to it, however, in this instance, I could also say that what should happen is that the compiler should create an anonymous class that contains a .Name and .Address property (of string), but then somehow the compiler would then try and set the new customer class to the anonymous class which obviously aren't the same type.  Unless of course you are saying that any class can be set to any anonymous class and VB will iterate through all the properties as it copies them, but why stop at anonymous classes then?  And of course that will lead to the idead that you should be able to set any class to any other class so long as they share the same (or a superset) of the properties.  Very messy.

    Would this work:
    Dim cust as Customer
    cust = { .Name="Me", .Address="123 Main" }

    I doubt it.  It would be nice sometimes to be able to do a shallow copy of one class to a differing class like that though, but using the equal sign to do so would cause many more problems than it is worth.  I would expect a different syntax like:
    Dim cust as new Customer With {.Name="Me",.Address="123 Main"}
    Dim cust as Customer
    cust=new Customer with { .Name="Me",.Address="123 Main"}
    as shorthand to:
    dim cust as Customer
    cust=new Customer
    with cust
       .Address="123 Main"
    end with
    Or possibly the syntax:
    Dim cust as new Customer With {"Me" as Name, "123 Main" as Address}
    Or both. Then you could use it as a short way of passing a class prefilled with properties to subs and function like:
    Call MySub(new Customer with (.Name.....))

    Now, that said, I find the shortcut to setting many properties to be far the least useful thing they showed, unless there was some very significant reason for it, like speed of setting many properties or some such.

    Of course my next question would be what about the new nullable types?

    Would these work:
    dim x = {1,2,3?,4}
    dim x = {1,2,null,4}
    dim x? = {1,2,3,4}
    dim y as integer? = 3: dim x ={1,2,y,4}
    as shorthand for
    dim x() as integer? = {1,2,3,4}

    Would this make an array of chars:
    Dim c = {"A"c,"B"c,"C"c}