Byte Blogger

- Charan Pasham

26 Views

Executing single file csharp files.

Have you ever wondered if .cs files can be executed without .csproj file, we can absolutely execute them with dotnet run command. This a new feature from .NET 10 (C#14)

       Console.WriteLine("Hello world");
       #!dotnet run
       Console.WriteLine("Hello world");
       chmod +x hello.cs

Reading command line arguments.

    if (args.length > 0)
    {
      string message = string.Join(' ', args);
      Console.WriteLine(message)
    }
    ./hello -- This is a command line.

The -- option indicates the all following arguments to be passed to the program.

Import nuget packages

   #:package System.CommandLine@2.0.0

For more info

File-Based-Programs