C# Environment GetEnvironmentVariable(String)

Description

Environment GetEnvironmentVariable(String) retrieves the value of an environment variable from the current process.

Syntax

Environment.GetEnvironmentVariable(String) has the following syntax.


public static string GetEnvironmentVariable(
  string variable
)

Parameters

Environment.GetEnvironmentVariable(String) has the following parameters.

  • variable - The name of the environment variable.

Returns

Environment.GetEnvironmentVariable(String) method returns The value of the environment variable specified by variable, or null if the environment variable is not found.

Example

The following example demonstrates the GetEnvironmentVariable method.


using System.IO;/*from   w w w.j  ava 2  s.  c  o  m*/
using System;
public class MainClass{
  public static void Main(String[] argv){  
    Environment.CurrentDirectory = Environment.GetEnvironmentVariable("windir");    
    DirectoryInfo info = new DirectoryInfo(".");
        Console.WriteLine("Directory Info:   "+info.FullName);
  }
}
    

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