views:

18

answers:

1

I think this is a pretty basic question, but I just want to clarify. If I have a variable with a null value, and pass it as a parameter that is optional, will the parameter get the null value, or the default value?

dim str As String = "foo"
dim obj As Object
//call 1
Request(str, str)
//call 2
Request(str)
//call 3
Request(str, obj)


public Function Request(byVal someVal As String, Optional ByVal someVal2 As String = "bar")
   ...

I know that call 1 will make someval == someval2 == "foo" inside the function, and call 2 will make someval == "foo" and someval2 == "bar" and call 3 will make someval == foo but what is someval2 equal to in call 3? nullable or bar?

Also - I'm relatively new to vb.net and I don't think I fully understand the null/nullable/nothing concept differences from C#

+2  A: 

"what is someval2 equal to in call 3? nullable or bar?" It will be null.

Well, actually, you can't do call 3 ... it will not compile because you can't pass an object as a string parameter. However, if you had dim obj as string = null, then it would be null.

Richard Hein