Visual Basic (Of T, or Of V) [英] Visual basic (Of T, or Of V)

查看:24
本文介绍了Visual Basic (Of T, or Of V)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在VB.NET中创建类或其他元素时,例如:

When creating classes or other elements in VB.NET, for example :

Public Class Class1(Of T)

End Class

(Of T )"在这段代码中是什么意思?

What does "(Of T )" mean in this code ?

推荐答案

(Of T) 是泛型类型参数.这意味着您可以:

(Of T) is a generic type parameter. It means that you can:

  • 在不知道 T 的类型的情况下,在类代码中引用 T.
  • 构造 Class1 类的实例,将任何类型 T 传递给它.
  • Refer to T in the class code, without knowing the type of T.
  • Construct instances of class Class1, passing any Type T into it.

这用于构造类,可以对不同类型进行操作,而无需在编译时知道类型.这对集合类非常有用,您可以在其中创建一次集合(例如:List),然后创建一个 List (Of String)List(DateTime) 等,适用于您可能需要的任何特定类型.

This is used to construct classes, that can operate on different types, without knowing the type at compile time. This is, among other things, very useful for collection classes, where you are able to create the collection once (Example: List), and then create a List (Of String) or List(Of DateTime) and so on, for any specific type you might need.

另外,请参阅这篇关于 VB.NET 中泛型的 MSDN 文章.

这篇关于Visual Basic (Of T, or Of V)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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