What adds "c" to the VB.NET character array?

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

Examples I found online using the IndexOfAny method include the "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 don’t see such a β€œc” after each character. What does "c" do? It's not obligatory?

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}) 
+6
source share
2 answers

This is a suffix for a literal like System.Char. So

 Dim foo As Char = "x"c 

Will compile (when the Strict option is set to On or Off). Without c it will be interpreted as a string. For more information about literal suffixes in VB.NET, see the MSDN Page: Constant and Literal Data Types .

+8
source

Actually just found the answer. I see that I received the answer, but adding this for clarity. The Char type is a numeric type, not a string type. The string characters "x" and "n" are not characters. Since this statement initializes an array of Char types, you cannot just add string literals. "C" identifies the compiler, which should be treated as Char, not a single character string.

http://bytes.com/topic/visual-basic-net/answers/438712-character-array-question

+2
source

Source: https://habr.com/ru/post/956493/


All Articles