New in .NET 10.0 [16]: Passing parameters in File-based Apps
The File-based Apps introduced in .NET 10.0 can also receive command-line parameters.
(Image: Pincasso/Shutterstock)
1 min. read
By
- Dr. Holger Schwichtenberg
Directly translating and starting C# files is called File-based Apps by Microsoft. You can pass additional parameters to it via the command line.
Parameters can be passed both in conjunction with class Program and the Main() method, as well as when using Top-Level Statements, because the compiler also provides the args variable for them.
The following code example shows an extended Hello World with parameters:
using System; // nicht notwendig, Standardnamensräume sind immer dabei, da <ImplicitUsings>enable</ImplicitUsings> gesetzt ist
var conf = args.FirstOrDefault() ?? "diesem Vortrag";
Console.WriteLine(System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription);
Console.WriteLine($"Hallo liebe Teilnehmerinnen und Teilnehmer bei \e[4;33;5m{conf}\e[0m!");
Console.WriteLine($"Kompilierungsmodus: {(System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported ? "JIT" : "AOT")}");
Videos by heise
Calling the File-based App with a parameter in Windows Terminal (Fig. 1)
(mho)