日期:2014-05-18  浏览次数:21105 次

string? 是什么意思,有什么功能?类似这样的定义还有么?
string? 是什么意思,有什么功能?类似这样的定义还有么?
Example:

string? address;
取值时用address.Value

------解决方案--------------------
有这样的用法吗?不可为空的值类型才能用作泛型类型或方法“System.Nullable<T>”中的参数“T”吧
string是引用类型啊,你这么定义没错?
------解决方案--------------------
C# code

class NullableExample
{
    static void Main()
    {
        int? num = null;
        if (num.HasValue == true)
        {
            System.Console.WriteLine("num = " + num.Value);
        }
        else
        {
            System.Console.WriteLine("num = Null");
        }

        //y is set to zero
        int y = num.GetValueOrDefault();

        // num.Value throws an InvalidOperationException if num.HasValue is false
        try
        {
            y = num.Value;
        }
        catch (System.InvalidOperationException e)
        {
            System.Console.WriteLine(e.Message);
        }
    }
}

------解决方案--------------------
类似这样的定义还有么?
---------
.NET 2.0以上...所有值类型都有对应的可空类型...因为其实它是泛型T?...见6,7,8楼...
------解决方案--------------------
C# code
string?
// 或
System.Nullable<string>
// 不成立,因为 string 本身就是可空的。

------解决方案--------------------
探讨
C# codestring?
// 或
System.Nullable<string>
// 不成立,因为 string 本身就是可空的。