C# Language Highlights: Null Coalescing Operator

  Рет қаралды 11,069

dotnet

dotnet

3 жыл бұрын

The null coalescing operator in C# is a really handy feature. Learn how it works in this short video from James ( / jamesmontemagno ) and Maira ( / mairacw )
🏫 Free self-guided learning for C# on Microsoft Learn: aka.ms/learn/csharp
?? and ??= operators (C# reference)
docs.microsoft.com/dotnet/csh...
First steps with C#
docs.microsoft.com/learn/path...
Get your questions answered on the Microsoft Q&A for .NET - aka.ms/dotnet-qa​
Learn .NET with free self-guided learning from Microsoft Learn: aka.ms/learndotnet
#DotNet #csharp

Пікірлер: 18
@EncryptedDream
@EncryptedDream 3 жыл бұрын
Great video
@BahawalTV
@BahawalTV 3 жыл бұрын
Nice!
@Lonchanick
@Lonchanick 7 ай бұрын
IN the first case I would say the question is "if the condition is true" but not "if it is null" , It could be confusing because we are not here evaluating if it is null but just evaluating a condition.
@riturajjana
@riturajjana 3 жыл бұрын
What if I want to print anything else other then 5. How can I do it with null coealsing ?
@larknoone565
@larknoone565 3 жыл бұрын
Does C# allows the creation of new operators unlike C++ ?
@pereirafabiosantos
@pereirafabiosantos 3 жыл бұрын
See this in the documentation: docs.microsoft.com/pt-br/dotnet/csharp/language-reference/operators/operator-overloading
@ethancox6967
@ethancox6967 3 жыл бұрын
No, like C++, C# does not allow the creation of new operators. See the official Microsoft documentation (which I have linked below) for a list of the overloadable operators. References: ========= - Can You Create New Operators in C#?: stackoverflow.com/questions/1040114/is-it-possible-to-create-a-new-operator-in-c - Microsoft C# Documentation: Overloadable Operators: docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/operator-overloading#overloadable-operators
@JoeBonez
@JoeBonez 3 жыл бұрын
You cannot create completely new operators, however you can override existing operators. Like, you can define “operator ==“ (which requires that you also override “operator !=“), or “operator *”. Implementing “IEquatable” implies (but does not require) “==“ and “!=“, while implementing “IComparable” implies (but again, does not require) “>”, “=“ and “
@joshemm4991
@joshemm4991 3 жыл бұрын
how about a = b ??= -1;
@mangkepweng3741
@mangkepweng3741 2 жыл бұрын
??= not supported in c#7.3
@vaishnaviwarang1583
@vaishnaviwarang1583 Жыл бұрын
what is an alternative to this? Mind helping me? I'm kind of stuck. I have a code where I need to assign a value of string to model object property . my code : @model HomeDetailsViewModel @{ ViewBag.Title = "Employee Details"; var photoPath = "/images/" + (Model.Employee.PhotoPath ?? "noimage.jpg"); // THIS LINE. }
@chefbennyj
@chefbennyj 3 жыл бұрын
Actually, thank goodness for conditional operators, coalescence, and nullable reference types. If it didn't exist, your code would be if if if if if if if if switch if if 😂
@jnicoulakos
@jnicoulakos 3 жыл бұрын
IF IF IF IF IF IF IF WOW! I hear you there! ;) I try to avoid the nested crap! :)
@chefbennyj
@chefbennyj 3 жыл бұрын
@@jnicoulakos I suppose using LINQ does handle the "if soup", using "select", first or default, but even "exists" has to live in an "if statement" 😂🤣😂🤣😂
C# Language Highlights: Records
6:13
dotnet
Рет қаралды 12 М.
The Right Way to Check for Null in C#
9:35
Nick Chapsas
Рет қаралды 94 М.
La revancha 😱
00:55
Juan De Dios Pantoja 2
Рет қаралды 61 МЛН
Неприятная Встреча На Мосту - Полярная звезда #shorts
00:59
Полярная звезда - Kuzey Yıldızı
Рет қаралды 2,5 МЛН
C# Nullable reference types - No more null reference exceptions!
18:06
The ?? Operator In 2 Minutes (Nullish Coalescing Operator)
2:08
C# Yield - Creating Iterators for beginners
5:52
tutorialsEU - C#
Рет қаралды 8 М.
List T and Collections of Data [Pt 12]  | C# for Beginners
12:08
C# Language Highlights: Default Interface Methods
5:53
dotnet
Рет қаралды 10 М.
C# Null-Conditional Operator (? Operator) Explained!
13:26
Gerald Versluis
Рет қаралды 6 М.
What are record types in C# and how they ACTUALLY work
15:36
Nick Chapsas
Рет қаралды 117 М.
C# DELEGATES in 8 minutes! Learn .NET FAST!
8:01
tutorialsEU - C#
Рет қаралды 41 М.
i love you subscriber ♥️ #iphone #iphonefold #shortvideo
0:14
Si pamerR
Рет қаралды 3,5 МЛН
ТОП-5 культовых телефонов‼️
1:00
Pedant.ru
Рет қаралды 18 М.
Samsung S24 Ultra professional shooting kit #shorts
0:12
Photographer Army
Рет қаралды 24 МЛН
ВЫ ЧЕ СДЕЛАЛИ С iOS 18?
22:40
Overtake lab
Рет қаралды 128 М.