what is ? operator in NotifyPropertyChanged

Advertisements

I have come across codes like

PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName));

I was trying to find what is the meaning of PropertyChanged? in the line of code above.

>Solution :

This is the syntax for null propagation which was introduced in c# 6.0. Here the ? is the null-conditional operator. This code is equivalent to:

if(!(PropertyChanged is null))
    PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propName));

Leave a ReplyCancel reply