Dim x as integer, x will return 0 when it have no filled?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Dear all

private x as integer
property X() as integer
get
return x
set(...)
end property

i don't want to get a value of 0, i want to get nothing, how can do that ar
 
In your code, x is of type Integer, which is a value type. All value types default to be equal to 0 when they are not initialized. A value type cannot be 'Nothing'.
 
Joe said:
private x as integer
property X() as integer
get
return x
set(...)
end property

i don't want to get a value of 0, i want to get nothing, how can do that ar

For integer values, nothing *is* 0. If you mean a null reference,
there's no such thing for a value type. See the Nothing keyword in MSDN
for more information.

(I think this would have been better posted to the VB.NET newsgroup,
btw - it has nothing to do with Windows Forms.)
 
* =?Utf-8?B?Sm9l?= said:
private x as integer
property X() as integer
get
return x
set(...)
end property

i don't want to get a value of 0, i want to get nothing, how can do that ar

VB.NET initializes all variables to 'Nothing'. For reference types,
that means, that they contain a reference pointing to 'Nothing'. You
can check if they are pointing to something using 'If foo Is Nothing'.
'Is' compares references. On the other hand, for value types like
'Integer', and all other structures, VB automatically assigns the
default valuue, so in other words, variables are initialized. You can
assign the default value to a variable of a value type by assinging
'Nothing' too. You can check if a value has been assigned by comparing
its value to 'Nothing' using the '=' operator. Notice that this will be
true if you explicitly assigned a value to the variable that is the
default value. For example, if you assign 0 to an 'Integer' variable,
comparing it to 'Nothing' will return 'True'.
 
Back
Top