---
title: "c# How to run program using Command line argument [on hold]"  
description: "c# How to run program using Command line argument [on hold]"  
author: "Anonymous User"  
published: 2013-09-04  
updated: 2013-09-04  
canonical: https://www.mindstick.com/forum/1449/c-sharp-how-to-run-program-using-command-line-argument-on-hold  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# c# How to run program using Command line argument [on hold]

How to run a [program](https://www.mindstick.com/blog/12337/scaling-up-your-mentorship-program) using [command line](https://www.mindstick.com/forum/158085/how-do-i-pass-command-line-arguments-to-a-node-js-program) argument for example my program only runs when i say a [string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp) [e.g](https://www.mindstick.com/forum/157370/how-to-swap-neighbor-characters-in-string-e-g-string-demo-would-be-edom) [Hello World](https://www.mindstick.com/forum/12912/how-to-show-hello-world-backbone-marionette-js) if this [value](https://www.mindstick.com/articles/23219/an-optimized-description-adds-value-to-experience-and-in-turn-effectively-guest-posting-packages) does not match then it should give an [error](https://yourviews.mindstick.com/view/88527/fixing-quickbooks-error-4120-reinstalling-vs-repairing).

if (args == null)

{

Console.WriteLine("cant be null"); // [Check](https://yourviews.mindstick.com/story/2248/never-forget-to-check-these-specifications-before-buying-a-mobile-phone) for null [array](https://www.mindstick.com/articles/335/jagged-array-in-c-sharp-dot-net)

}

if (args[0].Contains("Hello World"))

{

Console.WriteLine("True"); // Check for null array

}

else

{

Console.WriteLine("Error"); // Check for null array

}

Thanks in advance.

## Replies

### Reply by Sumit Kesarwani

Hi Ankita,\

Write this code in your main method(I am considering you are doing this in a Console application);

```
        if(args.Length <= 0)        {            //Error        }        else if(args.Length >= 1)        {            if(args[0] == @"Your argument")            {                //No error.            }            else            {               
//Error            }        }
```

Hope this helps you.


---

Original Source: https://www.mindstick.com/forum/1449/c-sharp-how-to-run-program-using-command-line-argument-on-hold

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
