C# Environment GetEnvironmentVariables()

Description

Environment GetEnvironmentVariables() retrieves all environment variable names and their values from the current process.

Syntax

Environment.GetEnvironmentVariables() has the following syntax.


public static IDictionary GetEnvironmentVariables()

Returns

Environment.GetEnvironmentVariables() method returns A dictionary that contains all environment variable names and their values; otherwise, an empty dictionary if no environment variables are found.

Example

The following example demonstrates the GetEnvironmentVariables method.


//from w  w w  .  j av a2  s .  c om

using System;
using System.Collections;

class Sample 
{
    public static void Main() 
    {
        IDictionary  environmentVariables = Environment.GetEnvironmentVariables();
        foreach (DictionaryEntry de in environmentVariables)
        {
            Console.WriteLine("  {0} = {1}", de.Key, de.Value);
        }
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version