From c38e408e5e6e87ff4936e5ec0d8bca420d143509 Mon Sep 17 00:00:00 2001 From: Marcello Lamonaca Date: Tue, 8 Jun 2021 13:44:55 +0200 Subject: [PATCH] Add notes about .NET 6 new features - global usings notes - null parameter checking - required properties --- .NET/C#/C#.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.NET/C#/C#.md b/.NET/C#/C#.md index e33f8a0..b453256 100644 --- a/.NET/C#/C#.md +++ b/.NET/C#/C#.md @@ -61,6 +61,9 @@ using System; // import the System Namespace using Alias = Namespace; // set an alias for a specific namespace using static System.Console; // statically import a class to use its static methods w/o qualification +// gloabl using [C# 10], should be in dedicated file +global using ; + namespace Namesapce; // [C# 10] //or namespace Namespace // namespace declaration @@ -553,6 +556,9 @@ variable ??= value; // if (variable == null) -> variable = value -- null coales // null checks through patter matching variable is null varaible is not null + +// null parameter checking [C# 10] +Method(Type argu!!) {} // will throwArgumentNullExceptionif arg is null ``` ### Nullable Attributes @@ -1462,6 +1468,9 @@ class Class // access backing field with the field keyword [C# 10] public Type Property { get; set => field = value; } + // required property [C# 10], prop myst be set at obj init (in constructor or initializer) + public required Type Property { get; set; } + // EXPRESSION-BODIED READ-ONLY PROPERTY public type Property => ;