当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - VB.Net Inline comments

问题描述:

Being a c# developer, I was very surprised to find i couldn't create inline comments within an array declaration.

In a test case I want to simulate 2 byte array packets coming through together:

Dim buffer As Byte() =

{

&HF5,

&H5,

&H53,

... many more bytes

&H1,

&H2,

&HCE,

&HF5, 'New packet starts here... this doesn't work :(

&H5,

&H53,

... many more bytes

&H1,

&H2,

&H1A

}

Surely I'm missing something, is it possible to place inline comments within an array declaration?

If not, is there a decent work around? Probably need to split array into 2 and then join them together?

Thanks in advance.

网友答案:

No it is not possible.
But, as you found out by yourself, in the future version - Visual Basic 14 (Visual Studio 2015) this will be possible New Language Features in Visual Basic 14

For current version you can create a properly named variable and use it in the array declaration

Dim newPacketStarts As Byte = &HF5

If you have a lot of hardcoded values - create constants with describable names

Const StartOfNewPacket As Byte = &HF5
Const AnotherValue As Byte = &H1
Const AnotherNewvalue As Byte = &HF53
'...

Declare array then

Dim buffer As Byte() = 
    {
        StartOfNewPacket,
        AnotherValue,
        AnotherNewvalue
    }
分享给朋友:
您可能感兴趣的文章:
随机阅读: