private string? typeOfContract
{
get { return (string?)ViewState["typeOfContract"]; }
set { ViewState["typeOfContract"] = value; }
}
稍后在代码中我这样使用它:
typeOfContract = Request.QueryString["type"];
我在声明 typeOfContract
行时遇到以下错误:
The type 'string' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'System.Nullable<T>'
有什么想法吗?基本上,我想在执行操作之前确保 "type"
存在于 QueryString
中。
最佳答案
System.String 是一个引用类型并且已经“可为空”。
可空
关于C# 可空字符串错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/187406/