您能传递一个“类型"吗?作为论点? [英] Can you pass a "type" as an argument?

查看:37
本文介绍了您能传递一个“类型"吗?作为论点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在VB.NET中执行以下操作,这可能吗?

I want to do something like the following in VB.NET, is it possible?

Function task(value as Object, toType as Type)

   Return DirectCast(value, toType)

End Function

推荐答案

是.有System.Type.您实际上可能想做一个泛型.

Yes. There is System.Type. You may actually want to do a Generic however.

Function SomeFunction(Of T)(obj As Object) As T
    '' Magic
End Function

这篇关于您能传递一个“类型"吗?作为论点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆