Jump to content

  • Log In with Google      Sign In   
  • Create Account


C# Compiler Error


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
11 replies to this topic

#1 Philosogamer   Members   -  Reputation: 136

Like
0Likes
Like

Posted 19 December 2011 - 02:07 PM

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?
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.

Sponsor:

#2 KazenoZ   Members   -  Reputation: 152

Like
0Likes
Like

Posted 19 December 2011 - 02:15 PM

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.

#3 Philosogamer   Members   -  Reputation: 136

Like
0Likes
Like

Posted 19 December 2011 - 02:29 PM

Nope. Still not working, and it's giving the same error.
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.

#4 KazenoZ   Members   -  Reputation: 152

Like
0Likes
Like

Posted 19 December 2011 - 02:36 PM

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.

#5 Philosogamer   Members   -  Reputation: 136

Like
0Likes
Like

Posted 19 December 2011 - 02:41 PM

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.
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.

#6 KazenoZ   Members   -  Reputation: 152

Like
0Likes
Like

Posted 19 December 2011 - 02:48 PM

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

#7 Imgelling   Members   -  Reputation: 222

Like
0Likes
Like

Posted 19 December 2011 - 02:48 PM

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.

#8 colinhect   Members   -  Reputation: 193

Like
0Likes
Like

Posted 19 December 2011 - 02:48 PM

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?

#9 Philosogamer   Members   -  Reputation: 136

Like
0Likes
Like

Posted 19 December 2011 - 03:00 PM


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?


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
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.

#10 Telastyn   Crossbones+   -  Reputation: 3726

Like
0Likes
Like

Posted 19 December 2011 - 03:28 PM

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.

#11 Philosogamer   Members   -  Reputation: 136

Like
0Likes
Like

Posted 19 December 2011 - 03:36 PM

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?
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.

#12 KazenoZ   Members   -  Reputation: 152

Like
1Likes
Like

Posted 19 December 2011 - 04:38 PM

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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS