如何在Visual Basic .NET中声明Char文字?

时间:2010-07-30 19:45:26

标签: vb.net literals

使用Option Strict On

Dim theLetterA As Char = "A"

返回有关将字符串"A"转换为Char的错误。

输入Char字面值的语法是什么?

3 个答案:

答案 0 :(得分:148)

使用后缀为C的单个字符串输入字符文字。

Dim theLetterA As Char = "A"C

答案 1 :(得分:3)

我会用CChar。 E.g:

 Dim theLetterA As Char = CChar("A")

有关CChar的详细信息,请访问MSDN网站https://msdn.microsoft.com/en-us/library/s2dy91zy.aspx

答案 2 :(得分:1)

在尝试将双引号作为字符文字的情况下,您需要使用额外的古怪VB格式:

Dim theQuote As Char = """"C

Dim theQuote As Char = CChar("""")