转换VB.Net数组到C# [英] Converting VB.Net Array to C#
问题描述
下面是一块VB.Net code的:
Here is a piece of VB.Net code:
Dim left As Object = NewLateBinding.LateGet(NewLateBinding.LateGet(sender, Nothing, "PressedLink", New Object(0 - 1) {}, Nothing, Nothing, Nothing), Nothing, "ItemName", New Object(0 - 1) {}, Nothing, Nothing, Nothing)
我的问题是与
New Object(0 - 1)
在线转换器转换它为下面的C#code:
The online converter converted it to the following C# code:
New Object[0 - 1]
我做了一些研究VB.Net数组code和它看起来像(0 - 1)只是告诉哪些号码索引开始和结束的。然而,在C#编译器认为这是一个消极1.我有一种感觉,在C#中它应该是:
I did some research on the VB.Net array code and it look like the (0 - 1) is just telling which numbers the index starts and ends on. However, in C# the compiler sees this as a negative 1. I have a feeling that in C# it should be:
New Object[2]
我只是想看看是否有人谁更熟悉VB.Net可以验证这一点对我来说,所以我知道我的正确与否这样做。
I just wanted to see if anyone who is more familiar with VB.Net can verify this for me so I know I am doing it correctly or not.
推荐答案
在VB.NET,声明数组时,您可以指定每个维度的最高指数,这些都是从零开始的。因此,新对象(0){}
实际上是一个项目的数组。正因为如此,与没有项目声明数组,你可以使用新对象(-1){}
。请参见这里了解更多详情。
In VB.NET, when declaring an array you specify the maximum index for each dimension, and these are zero based. So, New Object(0) {}
is actually an array with one item. Because of this, to declare an array with no items, you use New Object(-1) {}
. See here for more details.
在你的VB.NET code,新对象(0 - 1)
相同新对象(-1)
- 在 0 - 1
部分只是零负一,或-1,这意味着对象
。
In your VB.NET code, New Object(0 - 1)
is the same as New Object(-1)
- the 0 - 1
part is just zero minus one, or -1, meaning a zero-length array of Object
.
C#的等效只是新的对象[0]
,因为在C#中,你声明数组时指定元素的个数。
The C# equivalent is just new Object[0]
, since in C# you specify the number of elements when declaring an array.
这篇关于转换VB.Net数组到C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!