How would I prevent other developers from enter "" or " " into the following function/sub?
Public Sub MyFunction(MyString as String)
End Sub
' Call:
MyFunction("")
I want them to end up with a non compileable app.
How would I prevent other developers from enter "" or " " into the following function/sub?
Public Sub MyFunction(MyString as String)
End Sub
' Call:
MyFunction("")
I want them to end up with a non compileable app.
There is no way to prevent compilation based on what is passed to the string. You can, however, simply prevent the method from executing, like this:
Public Sub MyFunction(myString as String)
If Not String.IsNullOrWhitespace(myString) Then
' Do stuff here
End If
End Sub
Your other option is to throw an exception:
Public Sub MyFunction(myString as String)
If String.IsNullOrWhitespace(myString) Then
Throw New ApplicationException("No empty or whitespace strings allowed!")
Else
' Do stuff here
End If
End Sub