New in .NET 10.0 [16]: Passing parameters in File-based Apps
(Bild: Pincasso/Shutterstock)
The File-based Apps introduced in .NET 10.0 can also receive command-line parameters.
Directly translating and starting C# files is called File-based Apps by Microsoft [1]. 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 [2], 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")}");
(mho [3])
Don't miss any news – follow us on Facebook [4], LinkedIn [5] or Mastodon [6].
This article was originally published in German [7]. It was translated with technical assistance and editorially reviewed before publication.
URL dieses Artikels:
https://www.heise.de/-11226934
Links in diesem Artikel:
[1] https://www.heise.de/blog/Neu-in-NET-10-0-13-Kompilieren-und-Starten-einzelner-C-Dateien-11201372.html?from-en=1
[2] https://www.dotnet-lexikon.de/TopLevel%20Statement/lex/12051
[3] mailto:mho@heise.de
[4] https://www.facebook.com/heiseonlineEnglish
[5] https://www.linkedin.com/company/104691972
[6] https://social.heise.de/@heiseonlineenglish
[7] https://www.heise.de/blog/Neu-in-NET-10-0-16-Uebergabe-von-Parametern-in-File-based-Apps-11226764.html
Copyright © 2026 Heise Medien