This question already has an answer here: What do two question marks together mean in C#? 16 answers Well yeah that looks like an error. The code is looking whether Context.ContentDatabase or Context.Database aren't null , and then continues to use the former, even if it was null . The code should look like this: var database = Context.ContentDatabase ?? Context.Database; if (fieldC
这个问题在这里已经有了答案: C#中两个问号在一起意味着什么? 16个答案 好吧,这看起来像一个错误。 该代码正在查看Context.ContentDatabase或Context.Database是否为null ,然后继续使用前者,即使它为null 。 代码应该如下所示: var database = Context.ContentDatabase ?? Context.Database; if (fieldConfiguration == null && database != null) { Item obj = database.SelectSingleItem(
Possible Duplicate: What do two question marks together mean in C#? Is this a new feature added to C# 3.x ? eg public class HttpRequests { public string GetHtmlContent(this HttpRequest myRequest) { //do something return retStr ?? (retStr=new GetHtmlStr(urlStr)); } } The this and ?? are strange to me since I have not updated my know of C# for years.
可能重复: C#中两个问号在一起意味着什么? 这是一个添加到C#3.x的新功能吗? 例如 public class HttpRequests { public string GetHtmlContent(this HttpRequest myRequest) { //do something return retStr ?? (retStr=new GetHtmlStr(urlStr)); } } 这和? 对我来说很陌生,因为我多年来没有更新我对C#的了解。 我知道C#2.x. 对于条件if和返回值ie return a == 0 ?
This question already has an answer here: Unable to cast object of type 'System.DBNull' to type 'System.String` 10 answers What do two question marks together mean in C#? 16 answers DBNull isn't the same as null , so you can't use the ?? operator. You have to handle this case separately. Replace: Make = (string)(rdr["Make"] ?? ""), with: Make = (rdr["Make"] == S
这个问题在这里已经有了答案: 无法转换类型'System.DBNull'的对象来键入'System.String` 10个答案 C#中两个问号在一起意味着什么? 16个答案 DBNull与null不一样,所以你不能使用?? 运营商。 你必须分开处理这个案子。 更换: Make = (string)(rdr["Make"] ?? ""), 有: Make = (rdr["Make"] == System.DBNull.Value ? "" : (string)rdr["Make"]), SqlDataReader返回一个DBNull对象,它不是C#空
This question already has an answer here: What do two question marks together mean in C#? 16 answers ?? Null Coalescing Operator --> What does coalescing mean? 6 answers Unique ways to use the Null Coalescing operator 15 answers It is called a Null coalescing operator if the first part is null then use the next part, in your case if _command is null then it creates a new command e
这个问题在这里已经有了答案: C#中两个问号在一起意味着什么? 16个答案 ?? 空合并运算符 - >合并意味着什么? 6个答案 使用空合并运算符的独特方法15个答案 它被称为空合并运算符 如果第一部分为空,那么使用下一部分,在你的情况下,如果_command为空,那么它会创建一个新的command否则它将只使用_command 它是空的合并操作符。 这意味着如果这有一个值使用它,如果不使用下一个项目。 它对于可为空的
Possible Duplicate: What do two question marks together mean in C#? I am looking at an MVC project and the first line in a cshtml page is: @if (Model.DatabaseIssue ?? false) { } What does this mean? What is the double ?? and why is it used? that line uses Model.DatabaseIssue when Model.DatabaseIssue is not null , otherwise uses false . The ?? operator is called the null-coalescing
可能重复: C#中两个问号在一起意味着什么? 我正在查看一个MVC项目,并在cshtml页面的第一行是: @if (Model.DatabaseIssue ?? false) { } 这是什么意思? 什么是双? 为什么它被使用? 当Model.DatabaseIssue不为null ,该行使用Model.DatabaseIssue ,否则使用false 。 ?? ?? 运算符称为空合并运算符,用于为可为空的值类型以及引用类型定义默认值。 如果它不是null,则返回左边的操作数; 否则它返回右操作
This question already has an answer here: What do two question marks together mean in C#? 16 answers A ?? B is a shorthand for if (A == null) B else A or more precisely A == null ? B : A so in the most verbose expansion, your code is equivalent to: MemoryStream st; if(stream == null) st = new MemoryStream(); else st = stream; Basically it means if MemoryStream stream
这个问题在这里已经有了答案: C#中两个问号在一起意味着什么? 16个答案 A ?? B 是一个简写 if (A == null) B else A 或更准确地说 A == null ? B : A 所以在最繁琐的扩展中,您的代码相当于: MemoryStream st; if(stream == null) st = new MemoryStream(); else st = stream; 基本上这意味着如果MemoryStream stream等于null ,则创建MemoryStream st = new MemoryStream(); 所以在这种情况
Possible Duplicate: What do two question marks together mean in C#? can any one explain this syntax. protected string CompanyProductSeriesId { get { return Request.QueryString["CPGId"] ?? (ViewState["CPSId"] == null ? "" : ViewState["CPGId"].ToString()); } } I want to under stand the ?? in this syntax. A = B ?? C
可能重复: C#中两个问号在一起意味着什么? 任何人都可以解释这种语法。 protected string CompanyProductSeriesId { get { return Request.QueryString["CPGId"] ?? (ViewState["CPSId"] == null ? "" : ViewState["CPGId"].ToString()); } } 我想站在下面?? 在这个语法中。 A = B? C A = C如果B == NULL A = B如果B不是NULL 以
Possible Duplicate: What do two question marks together mean in C#? What is the usage of ?? in .Net? How it can be used to check while assigning the variables? Could you please write some code snippet to better explain the content ? Is it related with some nullable ? The operator '??' is called null-coalescing operator, which is used to define a default value for a nullable val
可能重复: C#中两个问号在一起意味着什么? 什么是使用? 在.Net中? 如何在分配变量时使用它来检查? 你能否写一些代码片段来更好地解释内容? 它与一些可空的相关吗? 运营商 '??' 被称为空合并运算符,该运算符用于为可为空的值类型以及引用类型定义默认值。 当我们需要将一个可为空的变量赋值为一个不可为空的变量时,它非常有用。 如果我们在分配时没有使用它,我们会得到类似的错误 不能隐式
Possible Duplicate: What do two question marks together mean in C#? I just came across the code below and not really sure what it means and can't google it because google omits the ?? int? x = 32; int y = x ?? 5; Is the second line some sort of if else statement, what does the ?? mean It's called the null-coalescing operator. If the value to the left of the ?? is null , then
可能重复: C#中两个问号在一起意味着什么? 我刚刚遇到下面的代码,并不确定它是什么意思,不能谷歌它,因为谷歌省略了?? int? x = 32; int y = x ?? 5; 是第二行某种if else语句,是什么?? 意思 它被称为空合并运算符。 如果值的左边的?? 是null ,然后使用右边的值?? 否则使用左手值。 展开: y = x == null ? 5 : x 要么 if(x == null) y = 5 else y = x if(x == null) y = 5 else y
Possible Duplicate: What do two question marks together mean in C#? What does the ?? mean in this C# statement? int availableUnits = unitsInStock ?? 0; if (unitsInStock != null) availableUnits = unitsInStock; else availableUnits = 0; This is the null coalescing operator. It translates to: availableUnits equals unitsInStock unless unitsInStock equals null , in which case availableU
可能重复: C#中两个问号在一起意味着什么? 什么? 在这个C#语句中是什么意思? int availableUnits = unitsInStock ?? 0; if (unitsInStock != null) availableUnits = unitsInStock; else availableUnits = 0; 这是空合并运算符。 它转化为: availableUnits等于unitsInStock除非unitsInStock等于null ,在这种情况下, availableUnits等于0。 它用于将可空类型更改为值类型。 ?? ?? 如果操作数不为nu