如何在 VisualBasic.NET 中声明字符文字?

Option Strict On:

Dim theLetterA As Char = "A"

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

输入 Char文字的语法是什么?

46260 次浏览

A character literal is entered using a single character string suffixed with a C.

Dim theLetterA As Char = "A"C

I would use CChar. E.g.:

 Dim theLetterA As Char = CChar("A")

Check the MSDN website https://msdn.microsoft.com/en-us/library/s2dy91zy.aspx for details on CChar.

In the case of trying to get a double quote as a character literal, you'll need to use the extra quirky VB format:

Dim theQuote As Char = """"C

Or

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