【问题标题】:Declare a VB.net method which will return list of integers [duplicate]声明一个将返回整数列表的 VB.net 方法[重复]
【发布时间】:2015-04-15 20:02:04
【问题描述】:

我得到了一个任务来改变 vb.net 项目的一些东西。由于我大部分时间都在使用 C#,所以我在某些事情上遇到了一些问题。

我想知道的是如何创建一个返回整数列表的方法,例如private List<int> NameOfMethod()

所以我正在尝试类似的东西:

Private Sub GetSourcesInfo() As

而且这个方法需要返回整数列表,我怎样才能在 VB.net 中实现呢?

【问题讨论】:

标签: c# vb.net c#-to-vb.net vb.net-to-c#


【解决方案1】:

那将是一个函数:

Private Function GetSourcesInfo() As List(Of Integer)
 ' code that builds a List(Of Integer)
End Function

【讨论】:

    【解决方案2】:

    在 VB 中,您可以使用关键字Of 指定泛型参数

    Private Function GetSourcesInfo() As List(Of Integer)
    

    这可能会导致括号链接语句对于来自 C# 的人来说看起来有点有趣,例如

    Dim someList As New List(Of Integer)()  ' Calls the constructor
    

    【讨论】:

      猜你喜欢
      • 2013-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-19
      • 2015-07-15
      • 1970-01-01
      相关资源
      最近更新 更多