| description | title | ms.date | f1_keywords | helpviewer_keywords | ms.assetid |
|---|---|---|---|---|---|
|
Compiler Error CS1001 |
Compiler Error CS1001 |
07/20/2015 |
CS1001 |
CS1001 |
327ad669-9c20-4fe8-a771-234878dbb90e |
Compiler Error CS1001
Identifier expected
You did not supply an identifier. An identifier is the name of a class, struct, namespace, method, variable, and so on, that you provide.
The following example declares a simple class but does not give the class a name:
public class //CS1001 { public int Num { get; set; } void MethodA() {} }
The following sample generates CS1001 because, when declaring an enum, you must specify members:
public class Program { enum Colors { 'a', 'b' // CS1001, 'a' is not a valid int identifier // The following line shows examples of valid identifiers: // Blue, Red, Orange }; public static void Main() { } }
Parameter names are required even if the compiler doesn’t use them, for example, in an interface definition. These parameters are required so that programmers who are consuming the interface know something about what the parameters mean.
interface IMyTest { void TestFunc1(int, int); // CS1001 // Use the following line instead: // void TestFunc1(int a, int b); } class CMyTest : IMyTest { void IMyTest.TestFunc1(int a, int b) { } }
See also
- Operators and expressions
- Types
I’m new to programming and am taking a C# class. I am getting compiler error CS1001 when I try to write this program.
I read the Compiler Error description (link below), but I’m really not getting it. What am I doing wrong?
http://msdn.microsoft.com/en-us/library/b839hwk4.aspx
Here is my source code:
using System;
public class InputMethodDemoTwo
{
public static void Main()
{
int first, second;
InputMethod(out first, out second);
Console.WriteLine("After InputMethod first is {0}", first);
Console.WriteLine("and second is {0}", second);
}
public static void InputMethod(out first, out second)
// The error is citing the line above this note.
{
one = DataEntry("first");
two = DataEntry("second");
}
public static void DataEntry(out int one, out int two)
{
string s1, s2;
Console.Write("Enter first integer ");
s1 = Console.ReadLine();
Console.Write("Enter second integer ");
s2 = Console.ReadLine();
one = Convert.ToInt32(s1);
two = Convert.ToInt32(s2);
}
}
According to the instructions, I’m supposed to have a method b (InputData) which pulls statements from method c (DataEntry)… Here are the instructions:
The InputMethod()in the InputMethodDemo program in Figure 6-24 contains repetitive
code that prompts the user and retrieves integer values. Rewrite the program so the
InputMethod()calls another method to do the work. The rewritten InputMethod()
will need to contain only two statements:one = DataEntry(«first»);
two = DataEntry(«second»);
Save the new program as InputMethodDemo2.cs.»
The InputMethodDemo they are referring to is the same program, except that it calls only one method (the InputMethod) instead of two.
The text I referred to above is «Microsoft® Visual C#® 2008, An Introduction to Object-Oriented Programming, 3e, Joyce Farrell»
Any advice/ help would be greatly appreciated.
- Remove From My Forums
-
Question
-
Hello to all,
We’ve all encountered a lot of errors and warnings whenever we debug our applications, but what I encountered recently was ridiculus!
Has anybody encountered an «Identifier expected» error that doesn’t tell you WHERE the error came from?
I’m using VS2005 and developing 2 intranet sites. The main intranet site works fine, but just recently, whenever I try to build (Ctrl + B) or debug (F5) my 2nd site, I get just one error:
«Identifier expected»
It goes like this:
Description: Identifier expected
File: <empty>
Line: <empty>
Column: <empty>
Project: <empty>I can’t debug by site’s codes because of this!
If there is something with my code, why wouldn’t the error list panel tell me what and where it is?!
Somebody please help me! I feel like an idiot already…
«Better be a geek than an idiot…»
Answers
-
Hello Falcon,
Compilation Error CS1001 means we did not supply an identifier for an Enum, parameter name, etc…
Please take a look at this article for more information and some samples that generate CS1001:
http://msdn.microsoft.com/en-us/library/b839hwk4(VS.80).aspxIn this case, based on the detailed output, the issue might be caused by UserLogs.aspx.cs. We will be very appreciated if you could post a code snippet of UserLogs.aspx.cs file for our further analysis.
Also, we could post threads in our ASP.NET Forum for more information. More specifically, if the code related to a purticular database, like SQL Server, MySql, or any database else, please take a look at this thread in our ASP.NET Forum.
Thanks a lot!
Best regards,
Roahn
-
Marked as answer by
Wednesday, March 18, 2009 5:05 AM
-
Marked as answer by
CS1001 – Identifier expected
Reason for the Error & Solution
Identifier expected
You did not supply an identifier. An identifier is the name of a class, struct, namespace, method, variable, and so on, that you provide.
The following example declares a simple class but does not give the class a name:
public class //CS1001
{
public int Num { get; set; }
void MethodA() {}
}
The following sample generates CS1001 because, when declaring an enum, you must specify members:
public class Program
{
enum Colors
{
'a', 'b' // CS1001, 'a' is not a valid int identifier
// The following line shows examples of valid identifiers:
// Blue, Red, Orange
};
public static void Main()
{
}
}
Parameter names are required even if the compiler doesn’t use them, for example, in an interface definition. These parameters are required so that programmers who are consuming the interface know something about what the parameters mean.
interface IMyTest
{
void TestFunc1(int, int); // CS1001
// Use the following line instead:
// void TestFunc1(int a, int b);
}
class CMyTest : IMyTest
{
void IMyTest.TestFunc1(int a, int b)
{
}
}
Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
i wrote it like he told me to do
using System;
namespace.treehouse{
class Program
{
static void Main()
{
Console.Write("Skriv hvor mange minutter du har arbejdet: "); string tid = Console.ReadLine() + tid; Console.Writeline("du har motioneret " + tid + " Minutter!"); }
}
}
and yet it says
Program.cs(2,9): error CS1001: Unexpected symbol `.’, expecting identifier
1 Answer

seal-mask
STAFF
Hi there, Rasmus! You’re close, but not quite there. There are currently two problems in your code that I can see and one is simply a spelling error.
You wrote this:
string tid = Console.ReadLine() + tid;
This will result in a syntax error as the + tid is not needed. You should erase the + tid from that line.
When you fix that, you will be presented with yet another syntax error and this is regarding the spelling/capitalization of WriteLine vs Writeline.
You wrote:
Console.Writeline("du har motioneret " + tid + " Minutter!");
But that should be:
// Note the capitalization of the "L" Console.WriteLine("du har motioneret " + tid + " Minutter!");
Give it a shot after you’ve corrected these small issues!
- Table of contents
- Error CS1001 (Identifier expected)
- Compiler Error CS1001
- What does “Unexpected symbol: ‘end-of-file’ “ mean?
Find the data you need here
We provide programming data of 20 most popular languages, hope to help you!
Previous PostNext Post
Error CS1001 (Identifier expected)
using System;
public class InputMethodDemoTwo
{
public static void Main()
{
int first, second;
InputMethod(out first, out second);
Console.WriteLine("After InputMethod first is {0}", first);
Console.WriteLine("and second is {0}", second);
}
public static void InputMethod(out first, out second)
// The error is citing the line above this note.
{
one = DataEntry("first");
two = DataEntry("second");
}
public static void DataEntry(out int one, out int two)
{
string s1, s2;
Console.Write("Enter first integer ");
s1 = Console.ReadLine();
Console.Write("Enter second integer ");
s2 = Console.ReadLine();
one = Convert.ToInt32(s1);
two = Convert.ToInt32(s2);
}
}
using System;
public class InputMethodDemoTwo
{
public static void Main()
{
int first, second;
InputMethod(out first, out second);
Console.WriteLine("After InputMethod first is {0}", first);
Console.WriteLine("and second is {0}", second);
Console.ReadLine();
}
public static void InputMethod(out int first, out int second)
//Data type was missing here
{
first = DataEntry("first");
second = DataEntry("second");
}
public static int DataEntry(string method)
//Parameter to DataEntry should be string
{
int result = 0;
if (method.Equals("first"))
{
Console.Write("Enter first integer ");
Int32.TryParse(Console.ReadLine(), out result);
}
else if (method.Equals("second"))
{
Console.Write("Enter second integer ");
Int32.TryParse(Console.ReadLine(), out result);
}
return result;
}
}
public static void InputMethod(out first, out second)
{
one = DataEntry("first");
two = DataEntry("second");
}
public static void InputMethod(out DataEntry first, out DataEntry second)
{
first = DataEntry("first");
second = DataEntry("second");
}
Compiler Error CS1001
public class //CS1001
{
public int Num { get; set; }
void MethodA() {}
}
public class Program
{
enum Colors
{
'a', 'b' // CS1001, 'a' is not a valid int identifier
// The following line shows examples of valid identifiers:
// Blue, Red, Orange
};
public static void Main()
{
}
}
interface IMyTest
{
void TestFunc1(int, int); // CS1001
// Use the following line instead:
// void TestFunc1(int a, int b);
}
class CMyTest : IMyTest
{
void IMyTest.TestFunc1(int a, int b)
{
}
}
What does “Unexpected symbol: ‘end-of-file’ “ mean?
using System;
namespace Treehouse.CodeChallenges
{
class Program
{
static void Main()
{
input = Console.ReadLine();
try
{
int input = int.Parse(output);
if (input == "quit")
{
string output = "Goodbye.";
continue;
}
else
{
string output = "You entered " + input + ".";
}
}
catch(FormatException)
{
}
}
using System;
using System.Diagnostics;
namespace Next
{
class MainClass
{
public static void Main(string[] args) // this is a method called "Main". It is called when the program starts.
{
Random numberGenerator = new Random();
int num01 = numberGenerator.Next(1, 21);
int num02 = numberGenerator.Next(1, 21);
int num001 = 1;
int num002 = 2;
int num003 = 3;
int num004 = 4;
int num005 = 5;
Console.WriteLine(" Welcome to XMATH!");
Console.WriteLine("------------------------------------------------------------------------------------------------------------------------");
Console.WriteLine(" Difficulty Selection n1 n2 n3 n4 n5 n6 n7 n8 n9");
Console.WriteLine("To START the first level press 1 nTo ENTER a code press 2nTo EXIT the game press 3 nTo see the RANKLIST press 4 nTo see the CREDITS press 5");
Console.WriteLine();
Console.WriteLine("------------------------------------------------------------------------------------------------------------------------");
int answer01 = Convert.ToInt32(Console.ReadLine());
if (num001 == answer01)
{
Console.WriteLine();
Console.WriteLine("------------------------------------------------------------------------------------------------------------------------");
Console.WriteLine();
Console.Write("What is " + num01 + " plus " + num02 + "?: ");
int answer = Convert.ToInt32(Console.ReadLine());
if (answer == num01 + num02)
{
Console.WriteLine("Well done! Your answer is correct.");
}
else
{
Console.WriteLine("Are you even trying?");
}
}
int answer02 = Convert.ToInt32(Console.ReadLine());
else if (num002 == answer02)
{
Console.WriteLine("------------------------------------------------------------------------------------------------------------------------");
Console.WriteLine(" Still in progress. n Please wait for updates");
Console.WriteLine("------------------------------------------------------------------------------------------------------------------------");
}
Console.ReadKey();
Console.WriteLine();
}
}
}
if (){
}
// you cannot put code here.
else if ()
{
}
Previous PostNext Post
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
public void RadarOnGUI() { Visuals.RadarList.Clear(); Rect radarRect = MenuHandler.RadarRect; Vector2 vector; vector..ctor(radarRect.center.x, radarRect.center.y + radarRect.height / 2f - 10f); Vector2 vector2; vector2..ctor(radarRect.center.x + radarRect.width / 2f - 10f, radarRect.center.y); Vector2 vector3; vector3..ctor(vector.x, vector2.y); int num = 20; float num2 = Math.Abs(radarRect.center.x - vector2.x); float num3 = num2 / (float)num; Vector3 position = Camera.main.transform.position; List<Zombie> list = new List<Zombie>(); foreach (ZombieRegion zombieRegion in ZombieManager.regions) { foreach (Zombie item in zombieRegion.zombies) { list.Add(item); } } foreach (Zombie zombie in list) { Vector2 vector4; vector4..ctor(zombie.transform.position.x - position.x, zombie.transform.position.z - position.z); float num4 = (float)Math.Round((double)(vector4.x * num3), 0); float num5 = (float)Math.Round((double)(vector4.y * num3), 0); num4 = -num4; Vector2 item2; item2..ctor(vector3.x + num4, vector3.y + num5); Log.l(vector3.ToString()); Log.l(item2.ToString()); Visuals.RadarList.Add(item2); } GUI.skin = HackDirector.sSkin; GUI.depth = 999; radarRect = MenuHandler.RadarRect; Vector2 vector5; vector5..ctor(radarRect.center.x, radarRect.center.y - radarRect.height / 2f + 20f); Vector2 vector6; vector6..ctor(radarRect.center.x - radarRect.width / 2f + 10f, radarRect.center.y); Vector2 vector7; vector7..ctor(vector6.x, vector.y); Vector2 vector8; vector8..ctor(vector2.x, vector.y); Vector2 vector9; vector9..ctor(vector6.x, vector5.y); Vector2 vector10; vector10..ctor(vector2.x, vector5.y); GL.PushMatrix(); GL.Begin(1); this.DrawingMaterial.SetPass(0); GL.End(); GL.PopMatrix(); GL.PushMatrix(); GL.Begin(1); this.DrawingMaterial.SetPass(0); GL.Color(Color.white); GL.Vertex3(vector.x, vector.y, 0f); GL.Vertex3(vector5.x, vector5.y, 0f); GL.Vertex3(vector6.x, vector6.y, 0f); GL.Vertex3(vector2.x, vector2.y, 0f); GL.Color(Color.black); GL.Vertex3(vector7.x, vector7.y, 0f); GL.Vertex3(vector8.x, vector8.y, 0f); GL.Vertex3(vector8.x, vector8.y, 0f); GL.Vertex3(vector10.x, vector10.y, 0f); GL.Vertex3(vector10.x, vector10.y, 0f); GL.Vertex3(vector9.x, vector9.y, 0f); GL.Vertex3(vector9.x, vector9.y, 0f); GL.Vertex3(vector7.x, vector7.y, 0f); GL.Color(Color.green); foreach (Vector2 input in Visuals.RadarList) { this.DrawSquare(input); } GL.End(); GL.PopMatrix(); } |
