How do you declare a Char literal in Visual Basic .NET?

谁都会走 提交于 2019-12-04 08:47:12

问题


With Option Strict On:

Dim theLetterA As Char = "A"

returns an error about converting the string "A" to a Char.

What is the syntax to enter a Char literal?


回答1:


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

Dim theLetterA As Char = "A"C



回答2:


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.




回答3:


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("""")


来源:https://stackoverflow.com/questions/3374842/how-do-you-declare-a-char-literal-in-visual-basic-net

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!