Nothing = Null?

proKrastinate

Member
Joined
Sep 14, 2002
Messages
15
Im trying to learn .net and am reading a book on it now. In the book there was mention to the value of Nothing available for declared objects. Is this the same as vb6s assigning a variable Null instead of ""?
 
kinda, you use that instead of null

There is a function calls DbNull or isDBNull or something, I cant remember exactly. Sometimes you can use that too, but I think you can do everything with Nothing
 
it said that I could also check for nothing by using something like

Code:
If x Is Nothing Then
or
If IsNothing(x) Then

When is the best time to use nothing as a value for a variable? Is there any good time to using "" ?
 
I was reading further and it stated that when an object is set to nothing it is set aside for garbage collection. And when the garbage collector comes by the object will be destroyed and its resources will be available again. I thought that null was a good way to give something a blank value but not for destroying the object. What is .NETs way of giving an object a null value without destroying the object?
 
Originally posted by proKrastinate
I was reading further and it stated that when an object is set to nothing it is set aside for garbage collection. And when the garbage collector comes by the object will be destroyed and its resources will be available again. I thought that null was a good way to give something a blank value but not for destroying the object. What is .NETs way of giving an object a null value without destroying the object?
you dont have to distroy all the objects. If your object is going out of scope then you are fine.
Sometimes your class may lock a resource and you will have to destroy it as soon as possible. You could force garbage collection, but most of the classes (like the graphic class) that are like this have a Dispose method. I think that frees the resources used by that class.....
I think you can also set your object to Nothing

and about when to use Nothing: you use that to check the the value of reference-types, like classes. And you have to use the Is operator if you are using Nothing.
 
Back
Top