none
如何为int类型赋空值 RRS feed

答案

  • 可以这样定义:

    int? i;

    i=null;

    2015年5月23日 14:26
  • hi,

    您可以使用nullable

    https://msdn.microsoft.com/zh-cn/library/1t3y8s4s.aspx


    秘訣無它,唯勤而已 http://www.dotblogs.com.tw/yc421206/

    2015年5月25日 14:30
  • Dear lctk:

    For non-nullable value types, Nothing in Visual Basic differs from null in C#. In Visual Basic, if you set a variable of a non-nullable value type to Nothing, the variable is set to the default value for its declared type. In C#, if you assign a variable of a non-nullable value type to null, a compile-time error occurs.

    you can reference as following:

    Using Nullable Types (C# Programming Guide)

    https://msdn.microsoft.com/zh-tw/library/2cf62fcy.aspx

    null 值。" data-guid="444b6129-12a4-9d22-8e2d-41015955f9a9" id="mt1" xml:space="preserve">Nullable types can represent all the values of an underlying type, and an additional null value. Nullable types are declared in one of two ways:

    System.Nullable<T> variable

    -or-

    T? variable

    Any value type may be used as the basis for a nullable type. For example:
    int? i = 10;
    double? d1 = 3.14;
    bool? flag = null;
    char? letter = 'a';
    int?[] arr = new int?[10];

    BR~

    David

    2015年5月25日 15:27

全部回复

  • 可以这样定义:

    int? i;

    i=null;

    2015年5月23日 14:26
  • hi,

    您可以使用nullable

    https://msdn.microsoft.com/zh-cn/library/1t3y8s4s.aspx


    秘訣無它,唯勤而已 http://www.dotblogs.com.tw/yc421206/

    2015年5月25日 14:30
  • Dear lctk:

    For non-nullable value types, Nothing in Visual Basic differs from null in C#. In Visual Basic, if you set a variable of a non-nullable value type to Nothing, the variable is set to the default value for its declared type. In C#, if you assign a variable of a non-nullable value type to null, a compile-time error occurs.

    you can reference as following:

    Using Nullable Types (C# Programming Guide)

    https://msdn.microsoft.com/zh-tw/library/2cf62fcy.aspx

    null 值。" data-guid="444b6129-12a4-9d22-8e2d-41015955f9a9" id="mt1" xml:space="preserve">Nullable types can represent all the values of an underlying type, and an additional null value. Nullable types are declared in one of two ways:

    System.Nullable<T> variable

    -or-

    T? variable

    Any value type may be used as the basis for a nullable type. For example:
    int? i = 10;
    double? d1 = 3.14;
    bool? flag = null;
    char? letter = 'a';
    int?[] arr = new int?[10];

    BR~

    David

    2015年5月25日 15:27