VB checks for null reference when passing ByRef

I have a function that takes a string by reference:

Function Foo(ByRef input As String) 

If I call it this:

 Foo(Nothing) 

I want him to do something different than if I would call it this way:

 Dim myString As String = Nothing Foo(myString) 

Is it possible to detect this difference in the method call method in VB.NET?

Edit

To find out why I would like to do this, I have two methods:

 Function Foo() Foo(Nothing) End Function Function Foo(ByRef input As String) 'wicked awesome logic here, hopefully End Function 

All logic is in the second overload, but I want to execute a different branch of the logic if Nothing was passed to the function than if a variable containing Nothing were passed.

+4
source share
2 answers

No. In any case, the method "sees" a link to a string ( input ) that does not indicate anything.

From the point of view of the method, they are identical.

+6
source

You can also add a Null control link:

1) before calling the function

 If myString IsNot Nothing Then Foo(myString) End If 

2) or inside a function

 Function Foo(ByRef input As String) If input Is Nothing Then Rem Input is null Else Rem body of function End If End Function 
0
source

All Articles