Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Console application running without program.cs file

Tags:

c#

I have created a simple console application in c#. Is there any option to run the application without the default program.cs file?

like image 416
Sinoy Devassy Avatar asked Nov 25 '13 11:11

Sinoy Devassy


People also ask

What is program cs file in C#?

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.

What does a console application run through?

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 ...

How do I run a .cs file in Visual Studio?

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.


2 Answers

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.

like image 154
Hossain Muctadir Avatar answered Oct 08 '22 10:10

Hossain Muctadir


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.

like image 9
Szymon Avatar answered Oct 08 '22 12:10

Szymon