C# Compiler Error

Started by
10 comments, last by KazenoZ 12 years, 4 months ago
Program '...\Shakespeare.exe' does not contain a static 'Main' method suitable for an entry point.


using System;
public class Shakespeare
{
public static void Main()
{
Console.WriteLine("Though this be maddness");
Console.WriteLine("yet there is method in it");
Console.WriteLine("-William Shakespeare");
}
}



I want to study C#, but I get an error from the compiler saying that I don't have a static Main method, when its right in front of my face. I'm using Visual Studio 2008. Anything I might be doing wrong?
[size=2]Happiness is not a life without problems, but rather the strength to overcome the problems that come our way. There is no such thing as a problem-free life; difficulties are unavoidable. But how we experience and react to our problems depends on us.
Advertisement
Seeing the using System; line there, I take it that this is your whole code, right? No Namespace?

Try something like this:
using System;
namespace Program1
{
public class Shakespeare
{
public static void Main()
{
Console.WriteLine("Though this be maddness");
Console.WriteLine("yet there is method in it");
Console.WriteLine("-William Shakespeare");
}
}
}



Mainly, just putting everything you had so far, inside a namespace scope.
Did you write this by hand by the way? Since using the new project option in VS it should've set that for you.

I hope that that's the issue, and not me missing something for misinterpreting =)

Welcome to programming.
Nope. Still not working, and it's giving the same error.
[size=2]Happiness is not a life without problems, but rather the strength to overcome the problems that come our way. There is no such thing as a problem-free life; difficulties are unavoidable. But how we experience and react to our problems depends on us.
I'm sorry mate, I'm not really fluent with C# by heart, I use it at work, but at home I prefer C++ myself, so I'm not very positive on the syntaxing.

I do suggest again that you use the project creation wizard in Visual Studio, and not write the template by hand, if you didn't do so already.
T_T Maybe I should just go back to learning C++ then. The only thing I can imagine doing with C# is using XNA, unless somebody else wants to take a crack at my error.
[size=2]Happiness is not a life without problems, but rather the strength to overcome the problems that come our way. There is no such thing as a problem-free life; difficulties are unavoidable. But how we experience and react to our problems depends on us.
I created a new Windows console project; commented out the generated code; and copy and pasted your code. Built without debugger (Ctrl+f5 for me).

Worked fine.

Just a few ideas...
1. Try creating a new project and copy/paste your code into it. Maybe a setting got messed up.
2. Rebuild the whole solution. Weird things happen to me and this fixes it sometimes (from menu, Build ->Rebuild Solution and the shortcut is set to Ctrl+Alt+F7 on mine)
my blog contains ramblings and what I am up to programming wise.
Iunno, I wouldn't do that if I were you.
It seems that you're very new to programming in general, right?

C# is really easier to get into and learn than C++ is, and XNA is far superior in learnability to newcomers than the competing alternatives for C++(SDL and SFML topping the mind), not to even mention how much simpler .NET is for C# than C++.

C# is very much superior for beginners, and I wouldn't turn down on it for just one compiling error that I'm sure someone will help you fix very soon anyway. Take in mind that programming requires patience after all =P

T_T Maybe I should just go back to learning C++ then. The only thing I can imagine doing with C# is using XNA, unless somebody else wants to take a crack at my error.



Compiler errors should never be a reason to switch languages.

Perhaps this Stackoverflow thread can help?

[quote name='Philosogamer' timestamp='1324327268' post='4895448']
T_T Maybe I should just go back to learning C++ then. The only thing I can imagine doing with C# is using XNA, unless somebody else wants to take a crack at my error.



Compiler errors should never be a reason to switch languages.

Perhaps this Stackoverflow thread can help?
[/quote]

Nah. His program is less basic than mine. I don't have a GUI, and when I went into the options to see if I could change the Startup object, there were no options on the drop down menu.

And im totally kidding when I say I'm gonna give up for 1 stupid error. XD
[size=2]Happiness is not a life without problems, but rather the strength to overcome the problems that come our way. There is no such thing as a problem-free life; difficulties are unavoidable. But how we experience and react to our problems depends on us.
That compiles for me fine in Visual Studio 2010 using a C# Console Application from the default menu.

I suspect your issues are with how you made your project.

This topic is closed to new replies.

Advertisement