Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Entry point
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===C#=== When executing a program written in [[C Sharp (programming language)|C#]], the [[Common Language Runtime|CLR]] searches for a static method marked with the <code>.entrypoint</code> IL directive, which takes either no arguments, or a single argument of type <code>string[]</code>, and has a return type of <code>void</code> or <code>int</code>, and executes it.<ref>{{cite web |url=http://msdn.microsoft.com/msdnmag/issues/04/02/NETConsoleApps/ |title=Console Applications in .NET, or Teaching a New Dog Old Tricks |publisher=Msdn.microsoft.com |date=2003-06-12 |access-date=2013-08-19 |archive-url=https://web.archive.org/web/20080204223443/http://msdn.microsoft.com/msdnmag/issues/04/02/NETConsoleApps/ |archive-date=2008-02-04 |url-status=dead }}</ref> <syntaxhighlight lang="csharp"> static void Main(); static void Main(string[] args); static int Main(); static int Main(string[] args); </syntaxhighlight> Command-line arguments are passed in <code>args</code>, similar to how it is done in Java. For versions of <code>Main()</code> returning an integer, similar to both C and C++, it is passed back to the environment as the exit status of the process. Since C#7.1 there are four more possible [[function signature|signatures]] of the entry point, which allow asynchronous execution in the <code>Main()</code> Method.<ref>{{cite web|url=https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.1/async-main.md|title=The official repo for the design of the C# programming language: Dotnet/Csharplang|website=[[GitHub]] |date=2019-08-26}}</ref> <syntaxhighlight lang="csharp"> static async Task Main() static async Task<int> Main() static async Task Main(string[]) static async Task<int> Main(string[]) </syntaxhighlight> The <code>Task</code> and <code>Task<int></code> types are the asynchronous equivalents of <code>void</code> and <code>int</code>. <code>async</code> is required to allow the use of asynchrony (the <code>await</code> keyword) inside the method.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)