proKrastinate Posted September 18, 2002 Posted September 18, 2002 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 vb6's assigning a variable Null instead of ""? Quote
Guest MrPolite Posted September 18, 2002 Posted September 18, 2002 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 Quote
Flyguy Posted September 18, 2002 Posted September 18, 2002 In VB6 you should also use Nothing: Set myObject = Nothing Quote
proKrastinate Posted September 18, 2002 Author Posted September 18, 2002 it said that I could also check for nothing by using something like 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 "" ? Quote
proKrastinate Posted September 18, 2002 Author Posted September 18, 2002 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 .NET's way of giving an object a null value without destroying the object? Quote
*Gurus* Thinker Posted September 18, 2002 *Gurus* Posted September 18, 2002 There is no such thing as a Null object. Either it is Nothing, or has been instantiated and uses resources. Quote Posting Guidelines
Guest MrPolite Posted September 20, 2002 Posted September 20, 2002 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 .NET's 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.