Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual C# Beginner Empty Project Help?

Tags:

c#

.net

winforms

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.

like image 631
7VoltCrayon Avatar asked Jun 17 '11 10:06

7VoltCrayon


People also ask

What is Visual C used for?

Microsoft Visual C++ is a integrated development environment (IDE) used to create Windows applications in the C, C++, and C++/CLI programming languages.

Is Microsoft Visual C free?

A fully-featured, extensible, free IDE for creating modern applications for Android, iOS, Windows, as well as web applications and cloud services.

Is Visual C necessary?

We don't recommend that you delete any Visual C++ redistributable, because doing so could make multiple applications on your computer stop working. Given how little space they take up and how broadly they are used, it doesn't seem worth the hassle to mess with your current ecosystem of standard library files.

Is Visual Studio C or C++?

C/C++ support for Visual Studio Code is provided by a Microsoft C/C++ extension to enable cross-platform C and C++ development on Windows, Linux, and macOS.


2 Answers

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.

like image 194
Jackson Pope Avatar answered Oct 10 '22 03:10

Jackson Pope


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!");
        }
   }
}
like image 22
CharithJ Avatar answered Oct 10 '22 03:10

CharithJ