【发布时间】:2025-12-12 19:55:02
【问题描述】:
我遇到过类似的代码
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName));
我试图在上面的代码行中找到PropertyChanged? 的含义。
【问题讨论】:
标签: c# wpf inotifypropertychanged
我遇到过类似的代码
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName));
我试图在上面的代码行中找到PropertyChanged? 的含义。
【问题讨论】:
标签: c# wpf inotifypropertychanged
这是 null 传播 的语法,它是 introduced in c# 6.0。这里的? 是空条件运算符。这段代码相当于:
if(!(PropertyChanged is null))
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propName));
【讨论】:
var handler = PropertyChanged; if (handler != null) { handler.Invoke... }。这是线程安全的,你的代码不是。