What does adding a “c” do in a VB.NET character array?

谁说我不能喝 提交于 2019-12-19 06:22:58

问题


I would like to use the String method IndexOfAny to check if a character exists in a specified string.

Examples I've found online, of using the IndexOfAny method include a "c" after each character in the character array when using VB.NET. However, when I look at examples of simple character arrays in VB.NET, I dont see any such "c" after each character. What does the "c" do? Is it optional?

Dim s1 As String = "Darth is not my father."
' Find the first index of either "x" or "n"
Dim i1 As Integer = s1.IndexOfAny(New Char() {"x"c, "n"c})

回答1:


That is a suffix for a literal of type System.Char. So

Dim foo As Char = "x"c

Will compile (when Option Strict is set to either On or Off). Without the c, it would be interpreted as a string. For more information about literal suffixes in VB.NET, take a look at the MSDN page, "Constant and Literal Data Types".



来源:https://stackoverflow.com/questions/19522703/what-does-adding-a-c-do-in-a-vb-net-character-array

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