Sign in to follow this  
IrvingSeverino

C# Compiler Error

Recommended Posts

IrvingSeverino    136
Program '...\Shakespeare.exe' does not contain a static 'Main' method suitable for an entry point.


[code]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");
}
}[/code]


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?

Share this post


Link to post
Share on other sites
KazenoZ    152
Seeing the using System; line there, I take it that this is your whole code, right? No Namespace?

Try something like this:
[code]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");
}
}
}

[/code]

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.

Share this post


Link to post
Share on other sites
KazenoZ    152
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.

Share this post


Link to post
Share on other sites
KazenoZ    152
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

Share this post


Link to post
Share on other sites
Imgelling    222
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)

Share this post


Link to post
Share on other sites
c_olin    197
[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.
[/quote]


Compiler errors should never be a reason to switch languages.

Perhaps [url="http://stackoverflow.com/questions/386831/troubleshooting-program-does-not-contain-a-static-main-method-when-it-clearl"]this Stackoverflow thread[/url] can help?

Share this post


Link to post
Share on other sites
IrvingSeverino    136
[quote name='colinhect' timestamp='1324327734' post='4895455']
[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.
[/quote]


Compiler errors should never be a reason to switch languages.

Perhaps [url="http://stackoverflow.com/questions/386831/troubleshooting-program-does-not-contain-a-static-main-method-when-it-clearl"]this Stackoverflow thread[/url] 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

Share this post


Link to post
Share on other sites
Telastyn    3777
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.

Share this post


Link to post
Share on other sites
IrvingSeverino    136
What I'm doing is:

File > New > Project > Empty Project ... (oh lol)


Hm. So my problem was probably that I wasn't using the [b][u]Solution Explore[/u][/b][u][b]r[/b][/u] to properly ad the .cs file. XD Are there other ways of properly adding 'items' to the project?

Share this post


Link to post
Share on other sites
KazenoZ    152
You should probably not use the empty project template, just take the console application like suggested above.
Should solve any problem.

As for adding 'items'(I suppose you mean code files?), just right click the Source or Header folder in the Solution Explorer according to your file, and click Add, you can then add a new item using a template like you did when creating the folder, or add an existing item you might want to import.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this