Ben Tam Ben Tam - 6 days ago 5
C# Question

CS5001 Program does not contain a static 'Main' method suitable for an entry point

I am new to C#. I'd be thankful if any body can show me why the following error is shown for code.

"CS5001 Program does not contain a static 'Main' method suitable for an entry point"

using System;

class test
{
void Foo(int x) { Console.WriteLine(x); }
void Foo(double x) { Console.WriteLine(x); }
void Foo(int x, float y) { Console.WriteLine(x); Console.WriteLine(y);}
void Foo(float x, int y) { Console.WriteLine(x); Console.WriteLine(y); }

void Main()
{
Foo(123); // int
Foo(123.0); // double
Foo(123, 123F); // int, float
Foo(123F, 123); // float, int
}
}

Answer

Your fixed code should look like this:

using System;

class test
{
    static void Foo(int x) { Console.WriteLine(x); }
    static void Foo(double x) { Console.WriteLine(x); }
    static void Foo(int x, float y) { Console.WriteLine(x); Console.WriteLine(y); }
    static void Foo(float x, int y) { Console.WriteLine(x); Console.WriteLine(y); }

    static void Main()
    {
        Foo(123);       // int
        Foo(123.0);     // double
        Foo(123, 123F); // int, float
        Foo(123F, 123); // float, int
    }
}