Reputation: 662
I'm a beginner to Visual Studio, I can create Windows From Projects and Console Projects just fine, but I can't compile Empty Projects,
The steps I take are:
Put the following code in the class:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; namespace Circles { class Program { static void Main(string[] args) { MessageBox.Show("Hello World!"); } } }
Then I hit compile, and it gives me this error:
Error 1 Program 'D:\C #\Projects\Circles\Circles\obj\x86\Debug\Circles.exe' does not contain a static 'Main' method suitable for an entry point Circles
The Properties build action is set to compile, but the Startup Object in the Project roperties is not set, is this causing the problem, if so what can I do?
EDIT: Question resolved see CharithJ's answer below. Thanks Guys.
Upvotes: 6
Views: 6428
Reputation: 47500
main
method name should be Main
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Circles
{
public class Program
{
public static void Main(string[] args)
{
MessageBox.Show("Hello World!");
}
}
}
Upvotes: 4
Reputation: 14640
You need to add the public
access modifier to the class and the main method, and make main begin with an upper-case m:
public class Program
{
public static void Main(string[] args)
{
MessageBox.Show("Hello World!");
}
}
Edit: As per comments, neither public access modifier is actually required.
Upvotes: 5
Reputation: 37172
Change static void main(string[] args)
to public static void Main(string[] args)
.
Its Main
not main
. Uppercase M
.
Upvotes: 3
Reputation: 333
Is there any specific reason why you don't use the Windows Form application template in Visual Studio?
Upvotes: 2
Reputation: 24372
change to
static void Main(string[] args)
(captial 'M')
You don't need to make it public.
Upvotes: 2
Reputation: 38580
You need to set the 'Startup Object' to be your Program
class.
Windows applications (that is applications with an output type of 'Windows Application') typically have an entry point that looks like this:
[STAThread]
public static void Main()
{
Application.EnableVisualStyles();
Application.Run(new SomeForm());
}
Whilst a 'Console Application' will typically have an entry such as:
public static void Main(string[] arguments)
{
...
}
Upvotes: 4