1

I'm trying to write an application which will be able to take a flag as an argument to allow the user to decide if they would like to run the application with or without a GUI. The solution which I am trying to implement is here, however, in the new Console template in C# you no longer have access to the

static void Main(string[] args) line, and so I am unsure where to place the [STAThread] attribute as the user suggested.

Callum
  • 31
  • 5
  • I don't understand what you mean by "you no longer have access to the `static void Main(string[] args)` line." Surely the program still has an entry point. – Robert Harvey Dec 26 '21 at 17:10
  • It does, but if you check out the second link, they've removed access to that line I believe in the newer version of C#. – Callum Dec 26 '21 at 17:13
  • Look [here](https://learn.microsoft.com/en-gb/dotnet/core/tutorials/top-level-templates#use-the-old-program-style). – Robert Harvey Dec 26 '21 at 17:17

1 Answers1

1

Unfortunately the MS document didn't seem to help much as I want to target .NET 6. The workaround which seems to work is


[STAThread]
static void Main(string[] args)
{
   Console.WriteLine("In the Main function");
}

Main(args); 
Callum
  • 31
  • 5