---
title: "Main () and Command-Line Arguments in C# Programming."  
description: "In this blog I am trying to explain the concept of Main() method and command line arguments using C# programming.  The Main method is the entry point"  
author: "Vijay Shukla"  
published: 2013-04-09  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/482/main-and-command-line-arguments-in-c-sharp-programming  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# Main () and Command-Line Arguments in C# Programming.

In this blog I am trying to [explain the concept](https://www.mindstick.com/forum/159605/explain-the-concept-of-unique-key-violation-error) of Main() method and command [line arguments](https://www.mindstick.com/forum/158085/how-do-i-pass-command-line-arguments-to-a-node-js-program) using [C# programming](https://www.mindstick.com/forum/156713/what-is-a-delegate-in-c-sharp-and-why-do-we-are-use-delegate-in-c-sharp-programming).\

The Main method is the [entry point](https://www.mindstick.com/interview/675/what-is-the-entry-point-for-window-based-application) of a C# [console application](https://www.mindstick.com/forum/160510/how-to-fetch-data-from-the-database-in-the-dot-net-console-application-using-c-sharp) or windows application. (In the term of libraries and services don’t require a Main method as an entry point.). When the application is started, the Main() method is the first method that is invoked. There can only be one entry point in a [C# program](https://www.mindstick.com/forum/156830/how-do-i-make-a-c-sharp-program-that-checks-for-given-array-by-user-which-elements-are-perfect-numbers). If you have more than one class that has a Main method, you must compile [your program](https://answers.mindstick.com/qa/33494/how-do-you-find-any-view-element-into-your-program-explain-for-example) with the /main compiler option to specify which Main method to use as the entry point.

```
class MyClass{    static void Main(string[] args)    {
        // Display the number of command line arguments:        System.Console.WriteLine(args.Length);
    }
}
```

##### Overview

1. The Main method is the entry point of an .exe program; it is where the program control starts and ends.\
2. Main is declared inside a class or struct. Main must be static and it should not be public.\
3. Main can either have a void or int return type.\
4. The Main method can be declared with or without a string [] parameter that contains command-line arguments. When using [Visual Studio](https://www.mindstick.com/articles/12378/visual-studio-for-mac-is-out-of-beta-preview-now-officially-available) to create Windows Forms applications, you can add the parameter manually or else use the Environment class to obtain the command-line arguments. Parameters are read as zero-indexed command-line arguments. Unlike C and C++, the [name of the program](https://answers.mindstick.com/qa/95369/what-is-the-name-of-the-program-launched-by-india-to-prevent-the-wastage-of-medical-oxygen) is not treated as the first command-line argument.

---

Original Source: https://www.mindstick.com/blog/482/main-and-command-line-arguments-in-c-sharp-programming

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
