What's new in C# version 12.0 in .Net Framework 8.0 | Latest version of C#

Опубликовано: 04 Октябрь 2024
на канале: OrBit of the CodinG
170
4

What new in C# version 12. Csharp Version. Upgraded topic of C#.
New Updates in C# 12.

1. Primary constructor -VS 2022.
2. Collection expression -VS 2022.
3. Inline Arrays
4. Optional parameters in lambda expressions.
5. ref readonly parameters.
6. Alias any type.
7. Experimental attribute
8. Interceptors.


Primary Constructor:
Primary constructor parameters may not be stored if they aren't needed.
Primary constructor aren't members of the class. for example a PC parameter named param can't be accessed as this.param.
Primary Constructor paramere can be assigned to.
Primary Constructor parameters don't becomes properites, except in record types.


Collection Expression:

Inlining other collections into these values is possible using a spread operator ....
int[] row0 = [1, 2, 3];
int[] row1 = [4, 5, 6];
int[] row2 = [7, 8, 9];
int[] single = [.. row0, .. row1, .. row2];

Inline arrays:

Inline arrays are used by the runtime team and other library authors to improve performance in your apps. Inline arrays enable a developer to create an array of fixed size in a struct type.
A struct with an inline buffer should provide performance characteristics similar to an unsafe fixed size buffer.