[英]How can I represent Dim order(4) As Int16 in C#?
如何在C#格式的VB的公共類中使用Dim order(4) As Int16
?
where,
order(0)=0;
order(1)=0;
order(2)=0;
order(3)=0;
這是默認值,只需使用正確的大小初始化數組即可。
請注意,您想要的長度為4,但是
Dim order(4) As Int16
初始化一個長度為5的數組。因此,您需要在VB.NET中這樣做:
Dim order(3) As Int16
而這在C#中(請注意,此處的長度4為4):
short[] order = new short[4];
這是以下內容的別名:
System.Int16[] order = new System.Int16[4];
它是一個數組,在c#中看起來像這樣(帶有初始化程序):
var i = new short[] {0,0,0,0};
看起來很簡單:
short[] order = new short[4];
你也可以明確指定缺省值,但0是隱含反正它是便宜不要這樣做,但是:
short[] order = new short[] {0, 0, 0, 0};
注意short
是System.Int16
的別名。 如果這是局部變量 (與field相對),則還可以使用var
進一步簡化它:
var order = new short[4];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.