0
如何防止其他开发人员将“”或“”输入到以下函数/子函数中?如何防止VB/ASP.Net中的空字符串函数参数
Public Sub MyFunction(MyString as String)
End Sub
' Call:
MyFunction("")
我希望他们最终得到一个不可编译的应用程序。
如何防止其他开发人员将“”或“”输入到以下函数/子函数中?如何防止VB/ASP.Net中的空字符串函数参数
Public Sub MyFunction(MyString as String)
End Sub
' Call:
MyFunction("")
我希望他们最终得到一个不可编译的应用程序。
根据传递给字符串的内容,无法防止编译。你可以,但是,简单地防止方法从执行,就像这样:
Public Sub MyFunction(myString as String)
If Not String.IsNullOrWhitespace(myString) Then
' Do stuff here
End If
End Sub
你的另一个选择是抛出一个异常:
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
嗨,好吧,我看到我无法达到我想要的。这样最终用户会收到这条消息。我不想要这个。不管怎样,谢谢你! –
我不认为一个字符串的内容可用在编译时。 –
嗯,我不是在谈论字符串变量,而是硬编码的字符串,例如“这是在” –