mirror of
https://github.com/m-lamonaca/dev-notes.git
synced 2025-04-08 11:56:41 +00:00
Add notes about .NET 6 new features
- global usings notes - null parameter checking - required properties
This commit is contained in:
parent
1e242ad4bf
commit
c38e408e5e
1 changed files with 9 additions and 0 deletions
|
@ -61,6 +61,9 @@ using System; // import the System Namespace
|
||||||
using Alias = Namespace; // set an alias for a specific 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
|
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>;
|
||||||
|
|
||||||
namespace Namesapce; // [C# 10]
|
namespace Namesapce; // [C# 10]
|
||||||
//or
|
//or
|
||||||
namespace Namespace // namespace declaration
|
namespace Namespace // namespace declaration
|
||||||
|
@ -553,6 +556,9 @@ variable ??= value; // if (variable == null) -> variable = value -- null coales
|
||||||
// null checks through patter matching
|
// null checks through patter matching
|
||||||
variable is null
|
variable is null
|
||||||
varaible is not null
|
varaible is not null
|
||||||
|
|
||||||
|
// null parameter checking [C# 10]
|
||||||
|
Method(Type argu!!) {} // will throwArgumentNullExceptionif arg is null
|
||||||
```
|
```
|
||||||
|
|
||||||
### Nullable Attributes
|
### Nullable Attributes
|
||||||
|
@ -1462,6 +1468,9 @@ class Class
|
||||||
// access backing field with the field keyword [C# 10]
|
// access backing field with the field keyword [C# 10]
|
||||||
public Type Property { get; set => field = value; }
|
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
|
// EXPRESSION-BODIED READ-ONLY PROPERTY
|
||||||
public type Property => <expr>;
|
public type Property => <expr>;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue