“Byte”的后缀(类型字符)是什么? VB.NET 中的数字常量?
只是出于好奇:
我知道我可以告诉编译器我是否希望将一个值解释为某种数字类型,例如整数(32 位有符号),这样可以将“I”(类型字符)附加到常量值:
Private Function GetTheAnswerAsInteger() As Integer
Return 42I
End Function
还有表示 Short 的“S”、表示 Decimal 的“D”等。
但是 Byte 的后缀是什么? 提示:这不是明显的“B”......
Just out of curiosity:
I know I can tell the compiler if I want a value to be interpreted as a certain numeric type, e.g. as Integer (32 bit signed), this way appending an "I" (type character) to the constant value:
Private Function GetTheAnswerAsInteger() As Integer
Return 42I
End Function
There's also "S" for Short, "D" for Decimal, etc.
But what is the suffix for Byte? Hint: it's not the obvious one "B"...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
没有一个。 如果您需要区分常量的整数和字节(例如,调用适当的重载),则需要进行强制转换。
(顺便说一下,C# 也是如此。)
MSDN 提供了确认:
还有一个类型字符和文字后缀列表。
There isn't one. If you need to distinguish between an integer and a byte (e.g. to call an appropriate overload) for a constant, you need to cast.
(The same is true in C#, by the way.)
MSDN provides confirmation:
There's also a list of type characters and literal suffixes.
https://roslyn.codeplex.com/discussions/542111
已集成到即将发布的 VB.NET 版本中,这就是它的工作方式:
https://roslyn.codeplex.com/discussions/542111
It has been integrated to the upcoming VB.NET release, and this is the way it will work:
这个答案并没有真正提供后缀,但它已经尽可能接近了。
如果您将扩展方法定义为
您可以像这样使用它:
This answer does not really provide a suffix, but it's as close as it gets.
If you define an extension method as
You can use it like this:
.NET 中没有字节文字。
There's no byte literal in .NET.