【问题标题】:Passing a new empty array as a parameter传递一个新的空数组作为参数
【发布时间】:2013-09-04 09:48:39
【问题描述】:

我有一个Dictionary(Of Integer, String())。当我添加一个新的 Key 时,我想添加一个具有定义长度的空数组,以便稍后添加和使用这些值。

Dim myDict As New Dictionary(Of Integer, String())()
Dim auxData(24) As String

myDict.Add(177, auxData)

有没有什么方法可以给Dictionary 添加一个值而不需要在值中使用变量?直接声明一个空字符串数组,指定长度即可。

类似:

myDict.Add(177, New String(24))

【问题讨论】:

  • 当您尝试该代码时会发生什么?
  • @JonSkeet 它尝试使用String constructor 并返回将整数转换为char 数组的错误。

标签: arrays vb.net .net-2.0


【解决方案1】:

只需在数组后添加{}

myDict.Add(177, New String(24){})

【讨论】:

  • 工作就像一个魅力,我不知道为什么我没有尝试。谢谢!
猜你喜欢
  • 1970-01-01
  • 2012-07-17
  • 1970-01-01
  • 1970-01-01
  • 2019-10-31
  • 1970-01-01
  • 2011-08-12
  • 2015-10-13
  • 2016-09-26
相关资源
最近更新 更多