什么"??" 意思?

Bri*_*ang 7 c#

我正在看ASP.NET MVC 1.0生成的代码,并且想知道; 双重问号意味着什么?

// This constructor is not used by the MVC framework but is instead provided for ease
// of unit testing this type. See the comments at the end of this file for more
// information.
public AccountController(IFormsAuthentication formsAuth, IMembershipService service)
{
    FormsAuth = formsAuth ?? new FormsAuthenticationService();
    MembershipService = service ?? new AccountMembershipService();
}
Run Code Online (Sandbox Code Playgroud)

有关:

?? Null Coalescing Operator - >合并是什么意思?

Jos*_*dan 32

这是空合并运算符.如果该值不为null,它将返回其左侧的值,否则返回右侧的值(即使它为null).它们通常以默认值结尾链接在一起.

查看此文章了解更多信息


Nat*_*n W 10

它意味着相同

If (formsAuth != null)
  FormsAuth = formsAuth;
else
  FormsAuth = FormsAuthenticationService();
Run Code Online (Sandbox Code Playgroud)