C# nullable string error

前端 未结 6 1957
梦如初夏
梦如初夏 2020-11-27 05:19
private string? typeOfContract
{
  get { return (string?)ViewState[\"typeOfContract\"]; }
  set { ViewState[\"typeOfContract\"] = value; }
}

Later

6条回答
  •  伪装坚强ぢ
    2020-11-27 05:44

    String is a reference type, so you don't need to (and cannot) use Nullable here. Just declare typeOfContract as string and simply check for null after getting it from the query string. Or use String.IsNullOrEmpty if you want to handle empty string values the same as null.

提交回复
热议问题