mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-08-12 09:44:24 +02:00
Merge pull request #1466 from csuich2/csharp-null-propagation
Added info C# null-propagation
This commit is contained in:
@@ -444,6 +444,9 @@ on a new line! ""Wow!"", the masses cried";
|
|||||||
// in case variable is null
|
// in case variable is null
|
||||||
int notNullable = nullable ?? 0; // 0
|
int notNullable = nullable ?? 0; // 0
|
||||||
|
|
||||||
|
// ?. is an operator for null-propogation - a shorthand way of checking for null
|
||||||
|
nullable?.Print(); // Use the Print() extension method if nullable isn't null
|
||||||
|
|
||||||
// IMPLICITLY TYPED VARIABLES - you can let the compiler work out what the type is:
|
// IMPLICITLY TYPED VARIABLES - you can let the compiler work out what the type is:
|
||||||
var magic = "magic is a string, at compile time, so you still get type safety";
|
var magic = "magic is a string, at compile time, so you still get type safety";
|
||||||
// magic = 9; will not work as magic is a string, not an int
|
// magic = 9; will not work as magic is a string, not an int
|
||||||
|
Reference in New Issue
Block a user