C# Features in 7.2

Facebook
Twitter
LinkedIn

Never miss a post!

Sign up for our newsletter and get FREE Development Trends delivered directly to your inbox.

You can unsubscribe any time. Terms & Conditions.
Categories

The following is the list of new features present in C# 7.2

 

Reference semantics with value types

C# 7.2 provides a new reference semantics

 

in.

in can be regarded as when a parameter is passed as const in c++. It indicates that the parameter is passed by reference but it cannot be modified by the function. The advantage is that it introduces optimisation as the variable is passed by reference.

private static double foo(in int a, in int b)

{  return a + b; }

 

ref readonly.

ref readonly allows you to return a value by reference but prevent changes to the reference.

 

private static ref readonly double foo(in int a, in int b)

{  return a + b; }

 

ref readonly x  = foo(10, 11);

 

Non-trailing named arguments

In C# 4.0 a new type of argument is introduced known as a named parameter. With this feature, you can specify the value of a parameter by parameter name regardless of its ordering of the parameters inside the method. The following is an example.

[code language=”csharp”]
int result = foo(b:10, a:11, c:12);

private int foo (int a, int b, int c){

}
[/code]

The limitation is that named parameters must appear before fixed parameters. Making the following result in a compilation error.

[code language=”csharp”]

int result = foo(b:10, a:11, 12);

private int foo (int a, int b, int c){

}

[/code]

This limitation has been removed in C# 7.2

Leading underscores in numeric literals

A feature added in 7.0 was the addition of number separator where _ (underscore) can be used to separate the number representation.

e.g. public const long BillionsAndBillions = 100_000_000_000;

C# 7.0 didn’t allow the _ to be the first character of the literal value. Hex and binary numeric literals may now begin with an _.

e.g. public int binaryValue = Ox_10_AB;

 

private protected access modifier

A new access modifier private protected is now available private protected

The member declared with this accessibility can be visible within the types derived from this containing type within the containing assembly. It is not visible to any types not derived from the containing type, or outside of the containing assembly. i.e., the access is limited to derived types within the containing assembly.

Facebook
Twitter
LinkedIn

Our website uses cookies that help it to function, allow us to analyze how you interact with it, and help us to improve its performance. By using our website you agree by our Terms and Conditions and Privacy Policy.