Do not require type specification for constructors when the type is known
See original GitHub issueDo not require type specification for constructors when the type is known.
Imagine this case:
Dictionary<string, List<int>> d = new Dictionary<string, List<int>>();
becomes:
Dictionary<string, List<int>> d = new();
Obviously, constructor arguments and object initialization would be allowed.
This might be a simple optimization given the above example, but there are longer type specifications out there.
But when applied to this:
XmlReader.Create(reader, new XmlReaderSettings{ IgnoreWhitespace = true });
it would become this:
XmlReader.Create(reader, new{ IgnoreWhitespace = true });
which is a lot more readable. In cases like this, the type is not really important, its properties are.
Issue Analytics
- State:
- Created 9 years ago
- Reactions:15
- Comments:24 (13 by maintainers)
Top Results From Across the Web
Target-typed new expressions - C# 9.0 draft feature ...
Do not require type specification for constructors when the type is known. Motivation. Allow field initialization without duplicating the type.
Read more >Why can't I define a default constructor for a struct in .NET?
NET, a value type (C# struct ) can't have a constructor with no parameters. According to this post this is mandated by the...
Read more >Constructors and member initializer lists
Constructors have no names and cannot be called directly. They are invoked when initialization takes place, and they are selected according to ...
Read more >6.5 Writing Object Type Call Specifications
If the specification declares only attributes or call specifications, then the body is not required. If you implement all your methods in Java,...
Read more >2.2. Creating and Initializing Objects: Constructors
Creating and Initializing Objects: Constructors¶. A Java class defines what objects of the class know (attributes) and what they can do (behaviors).
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is attractive as a counterpart to deconstruction, and we are considering it for a future version of C#.
I think it is useful for array initialization.