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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With