Permalink
Cannot retrieve contributors at this time
description | title | ms.date | f1_keywords | helpviewer_keywords | ms.assetid |
---|---|---|---|---|---|
Compiler Error CS1012 |
Compiler Error CS1012 |
07/20/2015 |
CS1012 |
CS1012 |
4acc5fe0-da47-4882-b7d8-557767d7cf03 |
Compiler Error CS1012
Too many characters in character literal
An attempt was made to initialize a char 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); } }
Sashaa_i 0 / 0 / 1 Регистрация: 02.11.2014 Сообщений: 64 |
||||
1 |
||||
27.12.2015, 12:11. Показов 23403. Ответов 3 Метки нет (Все метки)
return ‘pervy method’; — в этой строке выдает ошибку CS1012 Too many characters in character literal. Помогите пожалуйста разобраться что к чему и как исправить.
__________________
0 |
Администратор 15248 / 12287 / 4904 Регистрация: 17.03.2014 Сообщений: 24,883 Записей в блоге: 1 |
|
27.12.2015, 13:40 |
2 |
Сообщение было отмечено Sashaa_i как решение РешениеSashaa_i, строки в C# должны быть в двойных кавычках. Одинарные кавычки используются для символов.
1 |
0 / 0 / 1 Регистрация: 02.11.2014 Сообщений: 64 |
|
27.12.2015, 13:58 [ТС] |
3 |
всё равно ошибки Миниатюры
0 |
0 / 0 / 1 Регистрация: 02.11.2014 Сообщений: 64 |
|
27.12.2015, 14:04 [ТС] |
4 |
а нет, все хорошо, получилось, спасибо)
0 |
- Remove From My Forums
-
Question
-
User514441003 posted
//I need to write Number of days in month of Year method . However, the error CS1012: Too many characters in character literal. I think error in ch==’10’ and ch==’12’ . But how to solve it . Besides this , what is «ildasm» how to use it? thx ——————————————————————————————
using System; public class Hello { static void Main(string[] args) { int ch=Console.Read(); int state=0; switch (state) { case 0: if (ch ==’1′ || ch==’3′ || ch==’5′ || ch==’7′ || ch==’8′ || ch==’10’ || ch==’12’) { Console.WriteLine(«31»); } else if (ch ==
‘2’) goto case 2; else goto default; case 1: if (ch ==’4′ || ch==’6′ || ch==’9′ || ch==’11’) { Console.WriteLine(«30»); } else goto default; case 2: Console.WriteLine(«28 || 29!»); break; default: Console.WriteLine(«illegal character: » + (char) ch); break;
} } }
I am trying to create a string in a javascript function to resolve path for an image handler url, but I am getting the following error:
Compiler Error Message: CS1012: Too many characters in character literal
The Javascript function code is given in the Code section. The following line is highlighted red as the error:
var ImageUrlPath = <%= sting.format(‘PicHandler.ashx?Src={0}&ImgId={1}&CallingSource={2}&maxHeight={3}&maxWidth={4}, «HWDetails»,’ + HImgID.ClientID + ‘, «EnlargedImage»,’ + 600 + ‘,’ + 600 + ‘;’ ) %>
Please help me fix error in this line.
function ChangeCursor()
{
this.className ='linkClassPointer';
var control = document.getElementById('<% =HPost.ClientID %>').value;
alert (control);
if ((control==null) || (control=="") || (control.length==0))
var x=1
else
{
alert(control);
var ImageRightPaneID=document.getElementById('<% =ImageRightPane.ClientID%>');
var imgID = document.getElementById('<% =HImgID.ClientID %>').value;
var ImageUrlPath = <%= sting.format('PicHandler.ashx?Src={0}&ImgId={1}&CallingSource={2}&maxHeight={3}&maxWidth={4}, "HWDetails",' + HImgID.ClientID + ', "EnlargedImage",' + 600 + ',' + 600 + ';' ) %>
var imageSrc = <%= ResolveClientUrl(ImageRightPane.ImageUrl) %>;
ImageRightPaneID.onclick = "ImageRightPaneID.src='" + ImageSrc + "'";
}
return false;
}
Open in new window
-
#1
Hello! I would like to know how to fix this error and what it means I am writing for the first time. And I’m new to C#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour
{
public float speed;
private Rigidbody rb;
float MoveHorizontal;
float MoveVertical;
void Start()
{
rb = GetComponent<RigidBody>();
}
void FixedUpdate()
{
Vector3 movement = new Vector3(MoveHorizontal, 0.0f, MoveVertical);
rb.AddForce(movement * speed);
}
public void Up()
{
MoveVertical = 1f;
}
public void Down()
{
MoveVertical = -1f;
}
public void StopMoveVertical()
{
MoveVertical = of;
}
public void Left()
{
MoveVertical = 1f;
}
public void Right()
{
MoveHorizontal = -1f;
}
public void StopMoveHorizontal()
{
MoveHorizontal = 'of';
}
}
-
Skydiver
- Jul 1, 2022
In C#, strings are put between double quotes ("
), not single quotes ('
). The compiler is telling you that you are trying to put too many characters into a single character. There are special cases where you can use multiple characters to denote a single special characters. Ex. 't'
for a Tab character.
Once you get past that problem, you’ll run into the problem of trying to assign a string to a float
. C# is a strongly typed language. Variables (except dynamic
variables) have a single specific type. You can only assign values of that type to that variable.
-
#2
In C#, strings are put between double quotes ("
), not single quotes ('
). The compiler is telling you that you are trying to put too many characters into a single character. There are special cases where you can use multiple characters to denote a single special characters. Ex. 't'
for a Tab character.
Once you get past that problem, you’ll run into the problem of trying to assign a string to a float
. C# is a strongly typed language. Variables (except dynamic
variables) have a single specific type. You can only assign values of that type to that variable.
Last edited: Jul 1, 2022