Build with an Azure free account. Get USD200 credit for 30 days and 12 months of free services.

Start free today

C# Language Highlights: Target Typed new expressions

Play C# Language Highlights: Target Typed new expressions

The Discussion

  • User profile image
    RichardR
    True, target-typed new expressions will save you some keystrokes. But, is that really a wise choice for when you are reading the code 6 months, or 3 years from now? Or reading code someone else initially wrote? Having the type explicated stated in the code will probably make reading/understanding the code easier down the road.
  • User profile image
    Eliyahu

    Absolutely agree with RichardR. Also, I don't really appreciate saving on the type name. In case of many line, I will use copy/paste anyway, no typing.

  • User profile image
    jmoralesv

    2 hours ago

    Absolutely agree with RichardR. Also, I don't really appreciate saving on the type name. In case of many line, I will use copy/paste anyway, no typing.



    Both of you forget that the class type name is at the left hand side of the expression in the first example. In the second one, for the list of products, the type is also at the left. So there is no actual problem in the readability of the code.
  • User profile image
    Ilia101
    You are doing everything to convert C# with its maturity into Python garbage. So sad :(
  • User profile image
    Geoff

    In our workshop I already prohibit the use of var as a type keyword (in final code). I will equally prohibit this. This is because it is difficult to read and understand the classes being used without then having to run the mouse over everything. This shouldn't be about saving keystrokes - these mechanisms greatly reduce readability and intent. A one respondent suggested, coming back to this code in a few months is going to increase maintenance costs.

  • User profile image
    Typer
    How about this,just like javascript.{Name:"",Quantity:1}
  • User profile image
    Dylan

    Very useful? I don't think so... Very confusing? The more!
    This doesn't give me the "waaw" effect, really.
    Wonder if I still would know some time from now how everything was put together, let alone it's not even your code. Better going for the clear approach, even if it costs you a few keystrokes more
    And even then, the intelligent editor will provide you with some choices, even after a few keystrokes...

  • User profile image
    Zoli

    @jmoralesv


    You forget when you use it as parameters.
    E.g.:

    object.Do( new(), new() );

    REALLY??

Add Your 2 Cents