7VoltCrayon
7VoltCrayon

Reputation: 662

Visual C# Beginner Empty Project Help?

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:

  1. Create an Empty Project.
  2. Add a class, add a reference to System and System.Windows.Forms
  3. 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

Answers (6)

CharithJ
CharithJ

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

Jackson Pope
Jackson Pope

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

Pratik Deoghare
Pratik Deoghare

Reputation: 37172

Change static void main(string[] args) to public static void Main(string[] args).

Its Main not main. Uppercase M.

Upvotes: 3

RynoB
RynoB

Reputation: 333

Is there any specific reason why you don't use the Windows Form application template in Visual Studio?

Upvotes: 2

PaulB
PaulB

Reputation: 24372

change to

static void Main(string[] args)

(captial 'M')

You don't need to make it public.

Upvotes: 2

Paul Ruane
Paul Ruane

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

Related Questions