Live data from Hacker News

C# 9 top-level programs and target-typed expressions

developers.redhat.com

1–10 of 188 posts

Re: C# 9 top-level programs and target-typed expressions

#6
post #2

Unfortunately the new tricks can't be used when the codebase is still stuck on .net framework :(

Allegedly there's an upgrade path from .NET 4.8 to .NET 5.

if you have built anything on web forms, then you really have no way forward other than rewriting all that. That alone will keep many an enterprise locked on .NET Framework for quite some time.

Re: C# 9 top-level programs and target-typed expressions

#7
post #2

Unfortunately the new tricks can't be used when the codebase is still stuck on .net framework :(

There are ways, but definitely can be hard to get unstuck from framework. This came across my newsfeed this am: https://www.telerik.com/blogs/jump-starting-migration-dotnet... and also, the other day, dotnet rocks podcast had a guy on talking about an upgrade tool. I think it was this one: https://visualrecode.com/ He was also discussing the "Strangler Pattern": https://akfpartners.com/growth-blog/strangler-pattern-dos-an...

Re: C# 9 top-level programs and target-typed expressions

#9
To me, the benefit of "Target-typed new expressions" is more with bringing consistency to class-scope member declarations and method-scope member declarations, so these two can look the same, and a programmer only has to read one way of declaring new members in C#:

  public class MyClass {
   private readonly MyDependency _myDependency = new();

   public void MyMethodThatDoesWork() {
       MyVariable variable = new();
   }
  }
As opposed to the (now old, IMO) var syntax/Java-like syntax mixture:

  public class MyClass {
   private readonly MyDependency _myDependency = new MyDependency();

   public void MyMethodThatDoesWork() {
       var variable = new MyVariable();
   }
  }
Edited for HN formatting.

Re: C# 9 top-level programs and target-typed expressions

#10

To me, the benefit of "Target-typed new expressions" is more with bringing consistency to class-scope member declarations and method-scope member declarations, so these two can look the same, and a programmer only has to read one way of declaring new members in C#: public class MyClass { private readonly MyDependency _myDependency = new(); public void MyMethodThatDoesWork() { MyVariable variable = new(); } } As oppos…

I can't see var going anywhere, many times you aren't directly creating a new object, but getting a generated object from something ( like linq) which tends to have more complicated type signatures.
Post reply on HN