In this article, we will learn what the reasons for this error are and how to solve this error. To understand this error first you have to know what is a character literal.
Character literal:
A character literal is a type of literal that is used in programming to represent the value of a single character within the source code in a computer program. Languages that have dedicated character data types mostly include character literals.
Reason:
In C# this error occurs due to use to single quotes in place of double-quotes. We cannot use both for the same purpose. The single quotes are used to denote the single character that is of 2 bytes. or encapsulation whereas the double quotes are used for representing the string of characters.
Example:
var myChar = ‘=’
var myString = ‘==’
The most important thing is that the switch statement in C# works with strings. You cannot treat == or || as chars because these are not chars rather they are a sequence of characters. That’s why these can work in the switch because the switch works on strings instead of chars.
Example:
switch ( num) {
case “==”:
//something will here
Break;
default:
// It handles when no number is found
Break;
}