I suggest you ...

Allow new in C# without giving Type

see https://zoomicon.wordpress.com/2015/08/23/suggestion-allow-new-in-c-without-giving-type/ for a description of this suggestion

Instead of

List<CultureInfo> result = new List<CultureInfo>();

in C# I’d prefer to be able to write

List<CultureInfo> result = new ();

inside the () one would be able to pass contructor parameters and also they should be able to use

SomeClass v = new (someParam) { someProperty = …, otherProperty = … };

syntax, that is be able to initialize properties of the class

The idea is to allow syntax like:

SomeClass v = new (someParam) { someProperty = …, otherProperty = … };

and

Type v = new (…){…};

which is more general than

var v = new Type(…){…};

since you can then also do

someCollectionType.Add(new (…){…});

and

SomeMethod(new (…){…})

where the Type would be deduced from the param of the method (obviously if it is not overloaded with more versions with just 1 param)

NOTE THAT THESE ARE NOT ANONYMOUS TYPES, BUT INFERED TYPES FROM THE CONTEXT

In fact, the concept of anonymous types in C# could be merged with the suggested one, making the (…) optional if no constructor parameters are to be used (in anonymous types you only give the {…} part with the properties’ initialization).

The compiler would then resort to making a new anonymous type only if it can’t deduce a type from the usage context.

Of course if the (…) part (constructor parameters) are given, it would never try to make an anonymous type if it can’t find a matching type to instantiate with the respective constructor signature to call.

0 votes
Vote
Sign in
(thinking…)
Password icon
Signed in as (Sign out)
You have left! (?) (thinking…)
birbilis shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

0 comments

Sign in
(thinking…)
Password icon
Signed in as (Sign out)
Submitting...

Feedback and Knowledge Base