×

C# Tutorial

Basics of .Net

C# Basics

C# Fundamentals

C# Operators

C# Loops

C# Type Conversions

C# Exception Handling

C# String Class

C# Arrays

C# List

C# Stack

C# Queue

C# Collections

C# Character Class

C# Class and Object

C# Namespaces

C# Delegates

C# Constructors

C# Inheritance

C# Operator Overloading

C# Structures

C# File Handling

C# Convert.ToInt32()

C# Int32 (int) Struct

C# DateTime Class

C# Uri Class

C# Database Connectivity

C# Windows

C# Other Topics

C# Q & A

C# Programs

C# Find O/P

C# - Environment.GetCommandLineArgs() Method with Example

In this tutorial, we will learn about the C# Environment.GetCommandLineArgs() method with its definition, usage, syntax, and example. By Nidhi Last updated : March 30, 2023

Environment.GetCommandLineArgs() Method

The Environment.GetCommandLineArgs() method returns an array of strings that contains arguments passed on the command line.

Syntax

string [] Environment.GetCommandLineArgs();

Parameter(s)

This does not accept any parameter.

Return Value

This method returns an array of strings that contains arguments passed on the command line.

Exception(s)

  • System.NotSupportedException

C# Example of Environment.GetCommandLineArgs() Method

The source code to demonstrate the use of GetCommandLineArgs() method of Environment class is given below. The given program is compiled and executed successfully.

using System;

class Sample
{
    //Entry point of Program
    static public void Main()
    {
        string[] cmdArg;

        cmdArg = Environment.GetCommandLineArgs();

        Console.WriteLine("Command Line Arguments:");
        foreach (string arg in cmdArg)
        {
            Console.WriteLine("\t"+arg);
        }
    }
}

Here, we execute the above program using a command prompt to see all arguments passed on the command line.

Output

D:\>Program.exe 123 ABCD
Command Line Arguments:
        Program.exe
        123
        ABCD

C# Environment Class Programs »



Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.