HomeCSharpC# Error CS1012 – Too many characters in character literal

C# Error CS1012 – Too many characters in character literal

C# Error

CS1012 – Too many characters in character literal

Reason for the Error & Solution

Too many characters in character literal

An attempt was made to initialize a constant with more than one character.

CS1012 can also occur when doing data binding. For example the following line will give an error:

<%# DataBinder.Eval(Container.DataItem, 'doctitle') %>

Try the following line instead:

<%# DataBinder.Eval(Container.DataItem, "doctitle") %>

The following sample generates CS1012:

// CS1012.cs  
class Sample  
{  
   static void Main()  
   {  
      char a = 'xx';   // CS1012  
      char a2 = 'x';   // OK  
      System.Console.WriteLine(a2);  
   }  
}  

Leave a Reply

You May Also Like

This C# program calculates and displays an upper triangular matrix based on user input. Problem Statement: The program takes the...
This C# program serves as a demonstration of bitwise operators, which are fundamental operators used for manipulating individual bits in...
This C# program is designed to interchange or swap the columns of a matrix. A matrix is a two-dimensional array...