C# Environment SetEnvironmentVariable(String, String)

Description

Environment SetEnvironmentVariable(String, String) creates, modifies, or deletes an environment variable stored in the current process.

Syntax

Environment.SetEnvironmentVariable(String, String) has the following syntax.


public static void SetEnvironmentVariable(
  string variable,
  string value
)

Parameters

Environment.SetEnvironmentVariable(String, String) has the following parameters.

  • variable - The name of an environment variable.
  • value - A value to assign to variable.

Returns

Environment.SetEnvironmentVariable(String, String) method returns

Example

The following example tests whether an environment variable named APPDOMAIN exists in the current process.


using System;//w  w  w  .  ja  va 2 s .co m

public class Example
{
   public static void Main()
   {
      String envName = "AppDomain";
      String envValue = "True";

      if (Environment.GetEnvironmentVariable(envName) == null)
         Environment.SetEnvironmentVariable(envName, envValue);

    
   }
}

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