C# Environment GetEnvironmentVariables (EnvironmentVariableTarget)

Description

Environment GetEnvironmentVariables(EnvironmentVariableTarget) retrieves all environment variable names and their values from the current process, or from the Windows operating system registry key for the current user or local machine.

Syntax

Environment.GetEnvironmentVariables(EnvironmentVariableTarget) has the following syntax.


public static IDictionary GetEnvironmentVariables(
  EnvironmentVariableTarget target
)

Parameters

Environment.GetEnvironmentVariables(EnvironmentVariableTarget) has the following parameters.

  • target - One of the EnvironmentVariableTarget values.

Returns

Environment.GetEnvironmentVariables(EnvironmentVariableTarget) method returns A dictionary that contains all environment variable names and their values from the source specified by the target parameter; otherwise, an empty dictionary if no environment variables are found.

Example

The following example gets environment variables.


using System;/*from   w  ww.  j av a 2s  . c  o m*/
using System.Collections;
using Microsoft.Win32;

class Sample 
{
    public static void Main(){
        string str = Environment.GetEnvironmentVariable("A_GETSET_ENVAR_SAMPLE",
             EnvironmentVariableTarget.Process);
        Console.WriteLine(str);
    }

}

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