本文介绍了VB.NET 中的类型比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何比较 VB.NET 中的类型数据类型?我的代码:
How i can compare type data type in VB.NET?My code:
Private Function Equal(ByVal parameter As String, ByVal paramenterName As String, ByVal dataType As Type) As String
If dataType = String Then
return 1;
End If
End Function
有什么想法吗?
推荐答案
接受的答案存在语法错误.这是正确的解决方案:
The accepted answer has a syntax error. Here is the correct solution:
If dataType = GetType(String) Then
Return 1
End If
或
If dataType.Equals(GetType(String)) Then
Return 1
End If
或
If dataType Is GetType(String) Then
Return 1
End If
最后一种方法可能是最好的检查方法,因为如果对象为空,它不会抛出异常.
The last way is probably the best way to check because it won't throw an exception if the object is null.
这篇关于VB.NET 中的类型比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!