Why I'm Getting Cs1012: "Too Many Characters in Character Literal" and Cs0019

Why I'm getting CS1012: Too many characters in character literal and CS0019?

You're trying to use single quotes for string literals - that's invalid in C#. Single quotes are for character literals (char). You need double quotes for string literals. You also need parentheses for a method call:

webRequest.Headers["Authorization"] = "Bearer " + GetToken();

(Note that this has nothing to do with imgur or WebRequest - it's just normal C#.)

Links to MSDN explanations with samples:

  • CS1012 - "Too many characters in character literal"
  • CS0019 - "Operator 'operator' cannot be applied to operands of type 'type' and 'type'"

Error: too many characters in character literal asp.net

"too many characters in character literal" is caused by having a char-literal with too many characters in it.

You have probably mixed up the '-character and the "-character.

The error probably lies in your "android.aspx.cs"-file rather than the .aspx-file that you have provided.

Could you provide the code for that as well?

Well, your problems are right here:

<%# Bind('ModelID') %>

Replace your single-quotes with double-quotes and you will be golden!

<%# Bind("ModelID") %>

Same goes for all your Evals/Binds

Also see these questions:

Why I'm getting CS1012: "Too many characters in character literal" and CS0019?

Too many characters in character literal?

Console.Write(new string('* ', n) Too many characters in character literal

char name refers to character, and in '* ' code there are two characters: '*' and ' ' (whitespace). Therefore, it should be a string, characters and strings differ by type of quotes: ' vs ". Unfortunately, there is no overload of string constructor to accept another string and multiplier. So you need to reproduce same logic with different approach. One of them is below

var newStr = string.Join(string.Empty, Enumerable.Repeat("* ", 3));

Too many character in character literal

You need double quotes for strings in C#. Single quotes are for characters:

Eval("FirstColorCode")

Printing a sharp sign character

I am trying to print this Unicode character(and many others) but the Console displays a '?'.

The problem is not with the character, but it's the console not being configured the correct font to display this character.

You can manually set a console's Font, here's a tutorial on how to do it. I don't know of a way to set it programmatically (yet).

https://www.tenforums.com/tutorials/93961-change-console-window-font-font-size-windows.html

Here's a .net Fiddle: https://dotnetfiddle.net/xLvRq2

using System;

public class Program
{
public static void Main()
{
char kjfnv = '\u266F';
Console.WriteLine(kjfnv);
}
}

Output:



Update:

my personal set of applicable fonts in the console is very limited - meaning: I am not able to display the character.

However, the .net fiddle proves the methodology is correct - meaning: changing your console host, or find a way to make use of the correct font in Console should do the trick.

Here's a article on how to change fonts in powershell. Possibly a similar thing exists for the default console host: https://community.idera.com/database-tools/powershell/powertips/b/tips/posts/adding-more-fonts-to-powershell-console


@EricMovsessian: wasn't able to get this working without seriously needing to change some default values. For me this is not worth further investigation.

Keep in mind Console graphic capabilities are very limited, perhaps you want to consider an alternative technique, or just use the number sign # as a substitute



Related Topics



Leave a reply



Submit