No, that's not an example at all because in that code DD is not a reference type. A value type can never be a null reference so no warning will be given. THIS is a better example:The second line will cause that warning message to be displayed. It is telling you that no object has been assigned to the variable 'o' so if you try to access its members inside the method a NullReferenceException will result. I've already told you what to do about it:vb.net Code:
Dim o As Object Me.SomeMethod(o)If you specifically want the variable to refer to Nothing then explicitly state that. This will not stop any NullReferenceExceptions being thrown if you still don't use the variable properly, but it tells the compiler that you haven't just forgotten to assign a value so it will not display the warning.vb.net Code:
Dim o As Object = Nothing Me.SomeMethod(o)




Reply With Quote