vb.net 如何在 Visual Basic .NET 中声明 Char 文字?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3374842/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do you declare a Char literal in Visual Basic .NET?
提问by Jason Berkan
With Option Strict On
:
与Option Strict On
:
Dim theLetterA As Char = "A"
returns an error about converting the string "A"
to a Char
.
返回有关将字符串转换"A"
为 a的错误Char
。
What is the syntax to enter a Char
literal?
输入Char
文字的语法是什么?
回答by Jeff Mercado
A character literal is entered using a single character string suffixed with a C
.
使用以C
. 为后缀的单个字符串输入字符文字。
Dim theLetterA As Char = "A"C
回答by Alan Barksdale
I would use CChar. E.g.:
我会使用 CChar。例如:
Dim theLetterA As Char = CChar("A")
Check the MSDN website https://msdn.microsoft.com/en-us/library/s2dy91zy.aspxfor details on CChar.
有关 CChar 的详细信息,请查看 MSDN 网站https://msdn.microsoft.com/en-us/library/s2dy91zy.aspx。
回答by andyb
In the case of trying to get a double quote as a character literal, you'll need to use the extra quirky VB format:
在尝试将双引号作为字符文字的情况下,您需要使用额外古怪的 VB 格式:
Dim theQuote As Char = """"C
Or
或者
Dim theQuote As Char = CChar("""")