0

I am programming C# in Visual Studio Code with .NET 6. In .NET 6, an explicit main method is no longer necessary. Does anyone know how and where to include using directives like using System.Diagnostics?

This is what my program currently looks like:

await MeakeBreakfastAsync();

async Task MakeBreakfastAsync(){
    ...
}

static async Task<string> MakeCoffeAsync() {
    ...
}

static async Task<string> MakeToastAsync() {
    ...
}
rioV8
  • 24,506
  • 3
  • 32
  • 49
Z.J
  • 301
  • 1
  • 7
  • It's not about "explicit main method" per se but about [global using directives](https://stackoverflow.com/questions/69738921/where-are-the-using-statements-directives-in-net-6/69739444#69739444) and build in imports for different project types. – Guru Stron Aug 08 '22 at 10:33

1 Answers1

5

You still can place the usings on top like

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
 
Console.WriteLine("Hello World");
await Task.Delay(1000);
List<int> _ = new();

See Microsofts documentation for more details, especially on how to use <ImplicitUsings>disable</ImplicitUsings>.

Fruchtzwerg
  • 10,999
  • 12
  • 40
  • 49