C# 9 top-level programs and target-typed expressions
developers.redhat.com
C# 9 top-level programs and target-typed expressions
1–10 of 188 posts
Re: C# 9 top-level programs and target-typed expressions
#2Re: C# 9 top-level programs and target-typed expressions
#3Re: C# 9 top-level programs and target-typed expressions
#4Unfortunately the new tricks can't be used when the codebase is still stuck on .net framework :(
Re: C# 9 top-level programs and target-typed expressions
#5Re: C# 9 top-level programs and target-typed expressions
#6Unfortunately 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.
Re: C# 9 top-level programs and target-typed expressions
#7Unfortunately the new tricks can't be used when the codebase is still stuck on .net framework :(
Re: C# 9 top-level programs and target-typed expressions
#8If someone had told you that then you would have thought the world would have collapsed in the meantime.
Re: C# 9 top-level programs and target-typed expressions
#9 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
#10To 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…