会话变量引用后的问号(?) - 这是什么意思

时间:2017-03-28 16:09:41

标签: c# asp.net vb.net

我有一个代码片段来修改。在那里我发现了这样的语法。

Session("LightBoxID")?.ToString()

我不明白那个问号(?)是什么意思。没有谷歌搜索帮助我任何提示

2 个答案:

答案 0 :(得分:17)

在尝试呼叫txteditdescription.delegate = self 之前,它会对func textView(textView: UITextView, shouldChangeTextInRange range: NSRange, replacementText text: String) -> Bool { if (text == "\n") { textView.resignFirstResponder() return false } return true } 执行空值检查。

MSDN:Null-conditional Operators (C# and Visual Basic)

答案 1 :(得分:15)

它是Null-Conditional运算符 它是用于空检查的语法糖:

return str?.ToString();

将成为

if (str == null)
{
    return null;
}
return str.ToString();