作为一名 c#
开发人员,我很惊讶地发现我无法在 array
声明中创建 inline comments
。
在一个测试用例中,我想模拟 2 个 byte array
数据包一起通过:
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
}
当然我遗漏了什么,是否可以在数组声明中放置内联注释?
如果没有,是否有合适的工作?可能需要将数组拆分为 2,然后将它们连接在一起?
提前致谢。
最佳答案
不,这是不可能的。
但是,正如您自己发现的那样,在未来的版本中 - Visual Basic 14 (Visual Studio 2015) 这将成为可能 New Language Features in Visual Basic 14
对于当前版本,您可以创建一个正确命名的变量并在数组声明中使用它
Dim newPacketStarts As Byte = &HF5
如果你有很多硬编码值——创建具有可描述名称的常量
Const StartOfNewPacket As Byte = &HF5
Const AnotherValue As Byte = &H1
Const AnotherNewvalue As Byte = &HF53
'...
然后声明数组
Dim buffer As Byte() =
{
StartOfNewPacket,
AnotherValue,
AnotherNewvalue
}
关于c# - VB.Net 内联注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31718122/