你能传递一个"类型"作为参数吗?

Rob*_*cks 6 vb.net types casting

我想在VB.NET中做类似下面的事情,有可能吗?

Function task(value as Object, toType as Type)

   Return DirectCast(value, toType)

End Function
Run Code Online (Sandbox Code Playgroud)

Dan*_*ite 13

是.有System.Type.但是你可能真的想要做Generic.

Function SomeFunction(Of T)(obj As Object) As T
    '' Magic
End Function
Run Code Online (Sandbox Code Playgroud)