I have created a simple console application in c#. Is there any option to run the application without the default program.cs
file?
cs. Like C# console applications, ASP.NET Core has the Program class, which is an important class that contains the entry point to the application. The file has the Main() method used to run the application and it is used to create an instance of WebHostBuilder for creating a host for the application.
A console application is a computer program designed to be used via a text-only computer interface, such as a text terminal, the command-line interface of some operating systems (Unix, DOS, etc.) or the text-based interface included with most graphical user interface (GUI) operating systems, such as the Windows Console ...
It is easier to: Run Visual studio -> Make a new C# console project. This makes a project with a simple Program. cs file. You can just copy/paste in that, and run the project my clicking F5.
Program.cs
is not mandatory. Visual Studio creates a default Program.cs
with a Main
method for you to be able to run the application just after creating it.You only need an entry point. And for console application it is the Main
method.
You need to have a Main()
method in your console application. It doesn't have to be in program.cs
though.
From MSDN:
Every C# application must contain a single Main method specifying where program execution is to begin.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With