Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

string

vb.net

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})
like image 847
n00b Avatar asked Oct 22 '13 15:10

n00b


1 Answers

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".

like image 84
vcsjones Avatar answered Oct 22 '22 20:10

vcsjones