我想知道代码中的??标志C#.它是为了什么?我该如何使用它?
怎么样int??它是一个可以为空的int吗?
我想我记得在C#中看到类似于?:三元运算符的东西,它只有两个部分,如果不是null则返回变量值,如果是,则返回默认值.像这样的东西:
tb_MyTextBox.Text = o.Member ??SOME OPERATOR HERE?? "default";
Run Code Online (Sandbox Code Playgroud)
基本上相当于这个:
tb_MyTextBox.Text = o.Member != null ? o.Member : "default";
Run Code Online (Sandbox Code Playgroud)
这样的事情是存在的吗?我只是想象在某个地方看到这个?
我正在看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)