"Too many characters in character literal error"

Jinx picture Jinx · Apr 9, 2011 · Viewed 142.9k times · Source

I'm struggling with a piece of code and getting the error:

Too many characters in character literal error

Using C# and switch statement to iterate through a string buffer and reading tokens, but getting the error in this line:

case '&&':

case '||':

case '==':

How can I keep the == and && as a char?

Answer

Grant Thomas picture Grant Thomas · Apr 9, 2011

This is because, in C#, single quotes ('') denote (or encapsulate) a single character, whereas double quotes ("") are used for a string of characters. For example:

var myChar = '=';

var myString = "==";