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

Your email address will not be published. Required fields are marked *

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...