gpt4 book ai didi

c# - 返回可为空的字符串类型

转载 作者:可可西里 更新时间:2023-11-01 07:50:14 26 4
gpt4 key购买 nike

所以我有这样的东西

public string? SessionValue(string key)
{
if (HttpContext.Current.Session[key].ToString() == null || HttpContext.Current.Session[key].ToString() == "")
return null;

return HttpContext.Current.Session[key].ToString();
}

无法编译。

如何返回可为 null 的字符串类型?

最佳答案

String 已经是可以为 null 的类型。 Nullable 只能用于 ValueTypes。字符串是引用类型。

去掉“?”你应该可以开始了!

关于c# - 返回可为空的字符串类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/928398/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com