Upcoming features and enhancements in C# 7.2

Proposed features & enhancements in C# 7.2:

Non-trailing named arguments

Currently, a named argument can follow positional arguments

But currently a positional argument cannot follow a named argument

As per proposed enhancements in C# 7.2, named arguments are allowed to be used in non-trailing position, as long as they are used in their correct position.

private protected

Currently, C# supports following access modifiers:

private: can be accessed only in the same class or struct.

protected: can be accessed only in the same class or struct, or in a class that is derived from that class.

internal: can be accessed only in the same assembly.

protected internal: can be accessed in the assembly in which it is declared, or from within a derived class in another assembly.

With the proposed enhancement in C# 7.2, a member can be declared as private protected.  private protected member can be accessed within a subclass of its container if that subclass is in the same assembly as the member.

Readonly references (in parameters or ref readonly parameters)

Currently, Value-Type Parameters can be passed:

By Value – Passing a value-type variable to a method by value means passing a copy of the variable to the method. Any changes to the parameter that take place inside the method have no affect on the original data stored in the argument variable.

By Reference – If you want the called method to change the value of the parameter, you must pass it by reference, using the ref or out keyword.

With the proposed in parameters (ref readonly parameters) in C# 7.2, it would be possible to efficiently pass variables by reference, but without exposing the data to modifications.

conditional-ref

Pattern to conditionally bind a ref variable to one or another expression
The proposed syntax:

 Compile time enforcement of safety for ref-like types



Will share full working sample codes in my future posts on each of  above enhancement once they are released. I am looking forward to see private protected and in parameters in action.



Happy Coding !!!

Kapil Khandelwal

Web Developer, Blogger, Microsoft Certified Professional (MCP), DZone's Most Valuable Blogger (MVB)

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *