Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 使用option strict时从锯齿数组获取字符串值_Vb.net - Fatal编程技术网

Vb.net 使用option strict时从锯齿数组获取字符串值

Vb.net 使用option strict时从锯齿数组获取字符串值,vb.net,Vb.net,我刚开始使用option strict(基于另一个问题的建议),我被卡住了 我有一个包含更多数组的数组。第二个数组包含字符串。我不知道如何从第二个数组中获取字符串的值 dim sb as new stringbuilder public sub foobar({{"abcd", "efg"},{"hjik", "lmnop"}} for each arr in master sb.AppendLine(arr(0)) next end sub 但我有一个后期绑定错误。我理解为什么会出现

我刚开始使用option strict(基于另一个问题的建议),我被卡住了

我有一个包含更多数组的数组。第二个数组包含字符串。我不知道如何从第二个数组中获取字符串的值

dim sb as new stringbuilder
public sub foobar({{"abcd", "efg"},{"hjik", "lmnop"}}
 for each arr in master
  sb.AppendLine(arr(0))
 next
end sub

但我有一个后期绑定错误。我理解为什么会出现错误,但如何避免呢?

在函数请求中,您应该在vb.net中定义变量。
将“dim str”移动到函数的开头


假设master看起来与传递给foobar的内容相似,那么arr(0)将您添加到数组第一维的元素0,如果您希望附加每个第二级数组中的所有元素,则需要迭代该数组

使用Option Strict,您还需要声明每个变量的类型,因此它会变得非常“冗长”:


很抱歉,我简化了代码,以为这样会更简单。我不是定义变量,而是将arr(0)的内容写入stringbuilder。我将编辑问题代码不会编译事件添加缺少的
结束子项
“使用选项Strict,您还需要声明每个变量的类型”这不完全正确;它仅适用于类/模块范围内的“变量”,而不适用于方法内的局部变量。即使如此,它也依赖于
选项显式
选项推断
值。插图
Dim aryOfArrays()() As String = _
    New String()() {New String() {"1a", "1b"}, New String() {"2a", "2b"}}

For Each aryOfStrings As String() In aryOfArrays
    For Each strElement As String In aryOfStrings
        sb.AppendLine(strElement)
    Next
Next