C # 7.3 version has two major themes. The first topic provides the performance and unsafe code performance as good as the security code feature. The second topic provides incremental improvements to existing features. In addition, this release adds new compiler options.
The following new features to support the security code to get a better performance of the theme:
- It can be fixed without having to access a fixed field.
- You can reallocate
ref
local variables. - You can use
stackalloc
the initial value of the setting item array. - You can use any type of support mode
fixed
statements. - You can use other generic constraints.
To existing features the following enhancements:
- Tuples can be used to test
==
and!=
. - You can use a variable expression in multiple locations.
- Properties can be attached to the property field support automatic.
- A
in
method of distinguishing parameter analysis has been improved. - Overload resolution ambiguity situation is now becoming less.
The new compiler options are:
-publicsign
For enabling open source software (OSS) assembly signed.-pathmap
For providing the source directory mapping.
unsafe struct S { public fixed int myFixedField[10]; }
In earlier versions of C #, you need to access a fixed variable belonging to myFixedField
one of integers. Now, the code is compiled, without variable p
fixed to a single fixed
statement:
class C { static S s = new S(); unsafe public void M() { int p = s.myFixedField[5]; } }
Variable p
access myFixedField
a element. No need to declare a separate int*
variable. Please note that you still need unsafe
context. In earlier versions of C #, we declare a second fixed pointers:
class C { static S s = new S(); unsafe public void M() { fixed (int* ptr = s.myFixedField) { int p = ptr[5]; } } }
For more information, please refer to the fixed
statement of the article.
ref
the local variables are initialized, it may be reassigned to refer to different instances. Now compile the following code:
REF VeryLargeStruct refLocal = REF veryLargeStruct; // initialize refLocal = REF anotherVeryLargeStruct; // reallocating, reflecting different memory references.
For more information, please refer to the ref
return and ref
local variables , and foreach
articles.
was arr = new int [ 3 ] { 1 , 2 , 3 }; was Arr 2 = new int [] { 1 , 2 , 3 };
Now, you can use to stackalloc
perform the same array The declaration syntax:
int* pArr = stackalloc int[3] {1, 2, 3}; int* pArr2 = stackalloc int[] {1, 2, 3}; Span<int> arr = stackalloc [] {1, 2, 3};
For more information, please refer to the stackalloc
operator the article.
fixed
Statement supports a limited set of types. Starting C # 7.3, includes any return ref T
or ref readonly T
the GetPinnableReference()
type of the method are likely to fixed
. Adding this feature means that fixed
with System.Span <T> with the use and related types.
For more information, see the Language Reference fixed
Statement article.
Now, the type can be System.Enum or System.Delegate base class is specified for the constraint parameter type.
Now you can use the new unmanaged
constraint parameter to specify the type must be "unmanaged type." "Unmanaged type" is not a reference type, and does not contain any reference type at any level of nesting.
For more information, please refer to the where
generic constraints and constraint types parameters of the article.
These constraints will add to the existing types are incompatible change . Closed generic type constraints may no longer meet these new requirements.
==
and !=
. For more information, please refer to the tuple converting a text of Equation portion.
[field: SomeThingAboutFieldAttribute] public int SomeProperty { get; set; }
Property SomeThingAboutFieldAttribute
used in compiler-generated SomeProperty
support field. For more information, see C # Programming Guide properties .
in
parameter modifier, these two methods will lead to ambiguity:
static void M(S arg); static void M(in S arg);
Now, a read-only version of the referenced by overloading better than by a reload value (a first preceding example) is. To use read-only reference parameter called version, to be added before calling the method in
modifier.
For more information, please refer to the in
parameter modifier article.
out
syntax for variable declaration has been extended to include a field initializer, attribute initializer, a constructor initializer and query clauses. It allows the use of the code shown in the following example:
public class B { public B(int i, out int j) { j = i; } } public class D : B { public D(int i) : base(i, out var j) { Console.WriteLine($"The value of 'j' is {j}"); } }
In each version, the rules of overload resolution has been updated to resolve ambiguities method calls with the "obvious" choice situation. This release adds three new rules to help the compiler choose the obvious choice:
- When the process instance and the group contains static members, if the method in the absence of the receiver or context instance is invoked, the compiler discards instance members. If the method is invoked in the case of containing instances of the receiver, the compiler discards the static member. In the absence of the receiver, the compiler will add only static context of a static member, otherwise, would add static and instance members at the same time. When the receiver is unclear or the type of example, the compiler added simultaneously both. Static Context (which implicitly
this
instance receiver can not use) contains an undefinedthis
body member (e.g., static members), and the inability to use thethis
position (e.g., field initializer and a constructor initializer) is. - When a method of the type comprising a set of parameters do not satisfy certain constraints generic method thereof, the members removed from the candidate set.
- For group conversion method, the return type of the delegate candidate methods from the return type mismatch concentrated removed.
You will notice this change, because when you determine which method is better, you will find ambiguity overloaded methods with fewer compiler error.
-publicsign
The compiler option instructs the compiler to use the public key to sign the assembly. The assembly is marked as a signature, but the signature is taken from the public key. This option enables you to use the public key to sign the assembly building in open source projects.
For more information, see -publicsign compiler options article.
-pathmap
Compiler option instructs the compiler to generate source-path environment alternative source path map. -pathmap
Option controls the PDB file or as prepared by the compiler CallerFilePathAttribute written source path.
For more information, see -pathmap compiler options article.