零元素数组创建 [英] zero element array creation

查看:99
本文介绍了零元素数组创建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个零元素数组。我知道没有什么不是与零元素数组相同的

,因为我无法获得长度,或者

迭代,数组=无。我可以像这样制作一个零元素

数组,但它似乎有点矫枉过正:

Dim emptyArray as Byte()= System.Text.Encoding.Default .GetBytes(")


还有更好的办法吗?


Zytan

解决方案

Dim emptyArray()as Byte = New Byte(){}

Console.Writeline(emptyArray.Length)

>



Dim emptyArray as Byte()= New Byte(){}

Console.Writeline(emptyArray.Length)


我不知道为什么你可以两种方式写它。会有一个深奥的原因,但我只是不知道它是什么。


两种形式都可以编译成相同的IL。


我自己的偏好是第二种形式。

" Zytan" < zy ********** @ yahoo.comwrote in message

news:11 ******************** **@p10g2000cwp.googlegr oups.com ...


>我想创建一个零元素数组。我知道没有什么不是与零元素数组相同的

,因为我无法获得长度,或者

迭代,数组=无。我可以像这样制作一个零元素

数组,但它似乎有点矫枉过正:

Dim emptyArray as Byte()= System.Text.Encoding.Default .GetBytes(")


还有更好的办法吗?


Zytan


Dim emptyArray as Byte()= New Byte(){}


当然正确。


我不知道为什么你可以两种方式写它。会有一个深奥的原因,但我不知道它是什么。



我也想知道原因。


两种形式DO编译为相同IL。



好​​的。


我自己的偏好是第二种形式。



我也是。


再次感谢!!


Zytan


不要误会我Zytan - 我无意找出原因 - 在那个

的情况下我''我很高兴接受它就是这样。


当天没有足够的时间来追逐所有因素背后的原因。一个人碰到了。


我准备接受VB.NET的作者让''缺乏''存在

因为:


a。他们有一个短暂的失常

b。这是星期一早上/星期五下午晚些时候的早期

c。这样做有一个很好的理由

d。以上所有


我是否喜欢特定的''弱点'是另一回事,但我是

不会丢失任何睡在上面。


也就是说,各种各样的弱点确实可以在这里进行热烈的讨论。

。 :)

" Zytan" < zy ********** @ yahoo.comwrote in message

news:11 ******************** **@v33g2000cwv.googlegr oups.com ...


> Dim emptyArray as Byte()= New Byte(){}



当然正确。


>我不知道为什么你可以两种方式写它。会有一个深奥的原因,但我只是不知道它是什么。



我也想知道原因。


>两种形式都要编译相同的IL。



好​​的。


>我自己的偏好是第二种形式。



我也是。


再次感谢!!


Zytan


I want to make a zero element array. I know that Nothing is not the
same as a zero element array, since I can''t get the length of, or
iterate through, an array = Nothing. I could make a zero element
array like this, but it seems like overkill:

Dim emptyArray as Byte() = System.Text.Encoding.Default.GetBytes("")

Is there a better way?

Zytan

解决方案

Dim emptyArray() as Byte = New Byte() {}
Console.Writeline(emptyArray.Length)

or

Dim emptyArray as Byte() = New Byte() {}
Console.Writeline(emptyArray.Length)

I don''t know why you can write it both ways. There will be an esoteric
reason but I just don''t know what it is.

Both forms DO compile to identical IL.

My own preference is for the 2nd form.
"Zytan" <zy**********@yahoo.comwrote in message
news:11**********************@p10g2000cwp.googlegr oups.com...

>I want to make a zero element array. I know that Nothing is not the
same as a zero element array, since I can''t get the length of, or
iterate through, an array = Nothing. I could make a zero element
array like this, but it seems like overkill:

Dim emptyArray as Byte() = System.Text.Encoding.Default.GetBytes("")

Is there a better way?

Zytan


Dim emptyArray as Byte() = New Byte() {}

Right, of course.

I don''t know why you can write it both ways. There will be an esoteric
reason but I just don''t know what it is.

I''d like to know why, as well.

Both forms DO compile to identical IL.

Ok.

My own preference is for the 2nd form.

Mine, too.

Thanks again!!

Zytan


Don''t get me wrong Zytan - I have no inclination to find out why - In that
case I''m happy enough to accept that it just is.

There aren''t enough hours in the day to chase down the reasons behind all
the foibles that one comes across.

I''m prepared to accept that the writers of VB.NET let a ''foible'' exist
because:

a. they had a momentary aberration
b. it was early on a monday morning/late of friday afternoon
c. there is a really good reason for doing so
d. all of the above

Whether or not I like a particular ''foible'' is a different matter but I''m
not going to lose any sleep over it.

That said, the various ''foible''s do certanly make for som lively discussions
in here. :)
"Zytan" <zy**********@yahoo.comwrote in message
news:11**********************@v33g2000cwv.googlegr oups.com...

> Dim emptyArray as Byte() = New Byte() {}


Right, of course.

>I don''t know why you can write it both ways. There will be an esoteric
reason but I just don''t know what it is.


I''d like to know why, as well.

>Both forms DO compile to identical IL.


Ok.

>My own preference is for the 2nd form.


Mine, too.

Thanks again!!

Zytan


这篇关于零元素数组创建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆