C # compiler does not recognize overloaded main

The program "has more than one entry point:" Class.Main (). Compile with / main to specify the type containing the entry point.

I searched and searched and only found syntax to indicate the class of the entry point (/ main: class), but not the type. Can anyone help?

static void Main()
{
}

static void Main(string[] args)
{
}
+3
source share
4 answers

You cannot do this, basically.

You can only indicate that the type is the entry point, and not the main overload inside the type should be the entry point.

You can create a nested class containing one of them if you want to save the code in the same external type:

using System;
using System.IO;
using System.Text.RegularExpressions;

class Test
{
    class Parameterless
    {
        static void Main()
        {
        }
    }

    static void Main(string[] args){}
}

/main:Test, /main:Test.Parameterless , , Visual Studio.

+7

, main, : .

, "/main", (.. ), , (.. ), .

+4

Main() Main, . , . , , , .

+3

static void Main(string[] args)
{
    if (args == null)
    {

    }
    else
    {

    }
}

Not the best method, but it will work. This contradicts the concept of an application having 2 entry points.

+1
source

Source: https://habr.com/ru/post/1714993/


All Articles