我正在填写this answer中指定的List(Of Type)
,例如
Dim columnTypes = New List(Of Type) From {GetType(Integer), GetType(Integer),
GetType(String), GetType(String)}
我想将List
与实际Type
关键字进行比较,例如伪String
:
If columnTypes(i) = String Then
//do it because it's a String and not an Integer or Boolean or Object or...
如何有条件地确定此Type
中的List
?
答案 0 :(得分:3)
不要使用它的字符串表示,但是:
If columnTypes(0) = GetType(String) Then
Console.Write("I'm a string")
End If
或其他方式
If columnTypes.Contains(GetType(String)) Then
Console.Write("It contains a string")
End If
类型比较以这种方式工作,因为.NET框架4,以前的版本使用Is
:
If columnTypes(0) Is GetType(String) Then
Console.Write("I'm a string")
ElseIf columnTypes(0) Is GetType(Int32) Then
Console.Write("I'm an integer")
End If