sainath reddy
int i=null is wrong? how it make corect in .net
By sainath reddy in ASP.NET on Oct 25 2010
  • Jiteendra Sampathirao
    Nov, 2010 11


    We can declare like this:
    int? i = null;




    • 0
  • Srihari Chinna
    Nov, 2010 4

    Hi,

    primitive types can't be null. but to reduce the impedance missmatch between database and programing languages like C# MS has come up with the nullable types.

     

    Thanks,

    Chinna

     

    • 0
  • Prashanth Chindam
    Nov, 2010 3

    int? i=null; //nulable type

    Explaination:
    • Nullable types represent value-type variables that can be assigned the value of null.

    • The syntax T? is shorthand for System.Nullable<T>, where T is a value type. The two forms are interchangeable.

    • Assign a value to a nullable type in the same way as for an ordinary value type,
       for example int? x = 10; or double? d = 4.108;

    • Use the System.Nullable.GetValueOrDefault property to return either the assigned value, or the default value for the underlying type if the value is null, for example int j = x.GetValueOrDefault();

      For more information visit this link:
      http://msdn.microsoft.com/en-us/library/1t3y8s4s(VS.80).aspx




    • 0
  • Sushobhan Chakraborty
    Nov, 2010 1

    int is value type and therefore cannot be assigned a "null" value. You just have to
    declare the variable in the following form -

    int? i = null;

    Now this is valid.

    • 0
  • Kapil Deo Malhotra
    Oct, 2010 29

    int is not an object, it is primitive type which i think can not be null. You can set 0 of negative number.

    I am not sure what you want to accomplish here. If you can give your motive then we can provide solution for that.

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS