小编use*_*203的帖子

等待null合并运算符引发异常

我遇到一些奇怪的行为。

运行这段代码时:

var foo = await actionContext.RequestContext?.Principal?.ToUserTokenAsync() ?? UserToken.UnidentifiedUser;
Run Code Online (Sandbox Code Playgroud)

Principalnull在运行时,我得到一个空引用异常。

为什么它不只是返回-> UserToken.UnidentifiedUser

c# null-coalescing-operator async-await

0
推荐指数
1
解决办法
203
查看次数

标签 统计

async-await ×1

c# ×1

null-coalescing-operator ×1