Skip to content

Instantly share code, notes, and snippets.

@richlander

richlander/Program.cs Secret

Created Oct 13, 2020
Embed
What would you like to do?
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<Nullable>Enable</Nullable>
</PropertyGroup>
</Project>
using System;
Console.WriteLine("Hello World!");
@pmunin

This comment has been minimized.

Copy link

@pmunin pmunin commented Nov 10, 2020

what if there are multiple .cs files with its root level code? will they all execute? if yes, what will be the order of execution?

does it only work for apps or for DLLs too?

@contact4manoj

This comment has been minimized.

Copy link

@contact4manoj contact4manoj commented Nov 11, 2020

what if there are multiple .cs files with its root level code? will they all execute? if yes, what will be the order of execution?

Then, it would not work. This feature has been provided to facilitate rolling out single file programs - like the ones a developer of C program used to work with 😄

does it only work for apps or for DLLs too?

This feature is meant to work as a substitute for the effort to declare the public static void Main() method declaration. Note: This implies no usage of command line parameters.

@qbit86

This comment has been minimized.

Copy link

@qbit86 qbit86 commented Nov 14, 2020

Note: This implies no usage of command line parameters.

@contact4manoj

And if you want to access command line arguments, args is available as a "magic" parameter.
https://devblogs.microsoft.com/dotnet/c-9-0-on-the-record/#top-level-programs

@contact4manoj

This comment has been minimized.

Copy link

@contact4manoj contact4manoj commented Nov 15, 2020

And if you want to access command line arguments, args is available as a "magic" parameter.
https://devblogs.microsoft.com/dotnet/c-9-0-on-the-record/#top-level-programs

Thanks @qbit86.

@khellang

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment