CSharp.Net-Informations.com

  C# command line arguments




   Categories

    HOME
    VB.NET
    CSHARP


   














C# command line arguments

We can pass command line arguments to C# programs. The program accept arguments in the order of args[0], args[1] etc. The following program shows how to pass command line arguments to the cSHarp program. Open a new text document and copy and paste the following source code and save the file as "NewProg.cs"


         C# Source Code Download           Print Source Code
         C# command line arguments - Download
        
C# Tutorial

using System;

class NewProg
{
	static void Main(string[] args)
	{
		Console.WriteLine("Arguments-1 " + args[0]+"   Argument-2 "+args[1]);
		Console.ReadKey();
	}
}
		

Go to the command prompt and issue the following command for compilation.

csc NewProg.cs

After the successful compilation you will get NewProg.exe file

When you execute this C# program you have to pass two arguments with the filename.

NewProg test1 test2

you will get the output like Arguments-1 test1 Argument-2 test2

CSharp overview Related Contents
*     An overview of Microsoft .Net Framework
*     An introduction to C#
*     C# and VB.NET
*     C# and JAVA
*     C# sample programs
*     C# console based application
*     C# windows based application
*     C# command line tools

CSharp Related Topics
*     An overview of Microsoft CSharp
*     C# Language Tutorial
*     C# Statements Tutorial
*     C# Collection Tutorial
*     C# String Tutorial
*     C# File Operations Tutorial
*     C# Excel Tutorial
*     C# Crystal Reports Tutorial
*     CSharp Communication Tutorial
*     C# Ado.Net Tutorial and Source Code
*     C# ADO.NET data Providers Tutorial
*     C# Dataset Tutorial
*     C# DataAdapater Tutorial
*     Csharp DataView Tutorial
*     Csharp Remoting Tutorial
*     C# XML Tutorial
Search here for more CSharp Source Code :

  |  Home   |  SiteMap   |  About   |
net-informations.com (C) 2010 All Rights Reserved