简体   繁体   English

如何在C#中将Dim order(4)表示为Int16?

[英]How can I represent Dim order(4) As Int16 in C#?

How can I use Dim order(4) As Int16 which I have declared in public class of VB in C# format? 如何在C#格式的VB的公共类中使用Dim order(4) As Int16

where, 
order(0)=0;
order(1)=0;
order(2)=0;
order(3)=0;

That are default values, just initialize the array with the right size and you are finished. 这是默认值,只需使用正确的大小初始化数组即可。

Note that you want a length of 4 but 请注意,您想要的长度为4,但是

Dim order(4) As Int16

Initializes an array with the length 5. So you want this in VB.NET: 初始化一个长度为5的数组。因此,您需要在VB.NET中这样做:

Dim order(3) As Int16

and this in C# (note that it's 4 here for the length 4): 而这在C#中(请注意,此处的长度4为4):

short[] order = new short[4];

which is an alias for: 这是以下内容的别名:

System.Int16[] order = new System.Int16[4];

它是一个数组,在c#中看起来像这样(带有初始化程序):

var i = new short[] {0,0,0,0};

That looks like simply: 看起来很简单:

short[] order = new short[4];

You could also explicitly specify the defaults, but 0 is implicit anyway and it is cheaper not to do this, but: 你也可以明确指定缺省值,但0是隐含反正它是便宜要这样做,但是:

short[] order = new short[] {0, 0, 0, 0};

Note that short is an alias for System.Int16 . 注意shortSystem.Int16的别名。 If this is a local variable (as opposed to a field ), you can also simplify it further using var : 如果这是局部变量 (与field相对),则还可以使用var进一步简化它:

var order = new short[4];    

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM