• Advertisement
Sign in to follow this  

C# Compiler Error

This topic is 2254 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


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

Share this post


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

Share this post


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

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?

Share this post


Link to post
Share on other sites

[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

Share this post


Link to post
Share on other sites
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
What I'm doing is:

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


Hm. So my problem was probably that I wasn't using the Solution Explorer 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
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
Sign in to follow this  

  • Advertisement