问题
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