This is the code I have and I am trying to get rid of the error but there is always an error after error even with me looking it up:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Lesson02
{
    class Rectangle 
    {
        private double length;
        private double width;
        public Rectangle (double l, double w)
        {
            length = l;
            width = w;
        }
        public double GetArea()
        {
            return length * width;
        }
    }
}

It produces this error: 'Program c:/ ... does not contain a static 'Main' method suitable for an entry point.

I've already changed the Build Action properties and I still get this error. Please let me know what I am missing or need to add.

Edited 2 Years Ago by pritaeas: Moved to C#.

You need a function main(). Here are the valid signatures for main():

int main(void);
int main( int argc, const char** argv);
int main( int argc, const char* argv[]);

Note that the second and third versions are functionally (sic) identical. You can also use non-const arguments for argv, but that is not recommended as command line arguments are generally treated as constant values. In any case, modern compilers will require that main() return an integer (exit code).

As mentioned above you need a Main method.

The syntax above is not C# however and I think somebody got lost from his C++ forum :D

The default C# main method is the following:

static void Main(string[] args)
{
    // Code goes here
}

This is occuring in your case as it looks like you are trying to create classes for a ClassLib however the project will be console based and therefore you still need a Main program class in order for it to build. The other option is to make a Class Library project which does not require the Main method to build.

You can make a new class that looks like the following:

namespace Lesson02
{
    class MainProgramClass 
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Running");
            Console.ReadLine();
        }
    }
}

and it should compile then.

Edited 2 Years Ago by Mike Askew

This article has been dead for over six months. Start a new discussion instead.