C# Sugar & Improvements [6.0 to 10.0]

Hi everyone, just like me you came across to different projects with different versions of C# so is a common issue to forget the new features, the amenities of the version we are using.
So to ammend that I made something more interactive than an image …


This content originally appeared on DEV Community and was authored by Patricio Filice

Hi everyone, just like me you came across to different projects with different versions of C# so is a common issue to forget the new features, the amenities of the version we are using.
So to ammend that I made something more interactive than an image or a post, a project with examples, were you can run and see step by step each one of the features incorporated in each version, most of them are related with sugar sintax the others are new tools to simplify our work.
As an extra there is a url for each addon and C# version description.

You can click here to access te repo with the project

Features

For a more detailed explanation of what's new on each version:

C# 10.0

  • Assignment and declaration: There was a restriction where you couldn't mix the declaration and assignment of variables on the same line, that restriction was lifted.

  • File scoped namespace: Is a reduced way to declare a namespace saving space horizontally and vertically.

  • (PREVIEW) Generic attributes: As the name implies now is possible to create attributes based on a generic declaration, there are some limitations, and it can change on the final release but is a good tool to check on.

C# 9.0

  • Record: A new positional data type intended to be non mutable with its own traits closing a little more the gap with functional programming.

  • Targeted type: Reduces the redundant declarations when a type is implicit.

C# 8.0

  • Indexes and ranges for arrays: Its quicker and simpler to retrieve a specific element or a segment from an array.

  • Null coalescing: Reduces the checking and assignment when null is involved and wants to be avoided.

  • Pattern matching: Allows more advanced conditional statements, involving a syntax similar to functional pattern matching.

  • Using disposal: Eliminates the boilerplate declaration for disposables, for a block or a full method declaration.

C# 7.0

  • Bodied expression in a class: It's possible to use bodied expressions when declaring a constructor o destructor for a class.

  • Is operator for casting: The is operator was extended to allow outputting the casting result wich allows to reduce the needed code lines to check and use a casting.

  • Local function: We can declare our own methods inside the declaration of another method.

  • Out parameter with inline declaration: There is no further need to declare a variable before storing the value, we can declare and output to it on the same line.

C# 6.0

  • Name of: We can bind compile checking of a code definition (class, properties, variables, etc.) avoiding maintainability problems when plain text is related to an existing definition.

  • Null spreading: A way to avoid boilerplate null checking.

  • String interpolation: A less laborious way to dynamically format a string.


This content originally appeared on DEV Community and was authored by Patricio Filice


Print Share Comment Cite Upload Translate Updates
APA

Patricio Filice | Sciencx (2022-01-25T18:58:03+00:00) C# Sugar & Improvements [6.0 to 10.0]. Retrieved from https://www.scien.cx/2022/01/25/c-sugar-improvements-6-0-to-10-0/

MLA
" » C# Sugar & Improvements [6.0 to 10.0]." Patricio Filice | Sciencx - Tuesday January 25, 2022, https://www.scien.cx/2022/01/25/c-sugar-improvements-6-0-to-10-0/
HARVARD
Patricio Filice | Sciencx Tuesday January 25, 2022 » C# Sugar & Improvements [6.0 to 10.0]., viewed ,<https://www.scien.cx/2022/01/25/c-sugar-improvements-6-0-to-10-0/>
VANCOUVER
Patricio Filice | Sciencx - » C# Sugar & Improvements [6.0 to 10.0]. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/01/25/c-sugar-improvements-6-0-to-10-0/
CHICAGO
" » C# Sugar & Improvements [6.0 to 10.0]." Patricio Filice | Sciencx - Accessed . https://www.scien.cx/2022/01/25/c-sugar-improvements-6-0-to-10-0/
IEEE
" » C# Sugar & Improvements [6.0 to 10.0]." Patricio Filice | Sciencx [Online]. Available: https://www.scien.cx/2022/01/25/c-sugar-improvements-6-0-to-10-0/. [Accessed: ]
rf:citation
» C# Sugar & Improvements [6.0 to 10.0] | Patricio Filice | Sciencx | https://www.scien.cx/2022/01/25/c-sugar-improvements-6-0-to-10-0/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.