The source code to demonstrate the use of SetEnvironmentVariable() method of Environment class is given below. The given program is compiled and executed successfully.
using System;
using System.IO;
class Sample
{
//Entry point of Program
static public void Main()
{
string Var_Name = "VAR1";
string Var_Value = "True";
if (Environment.GetEnvironmentVariable(Var_Name) == null)
{
Environment.SetEnvironmentVariable(Var_Name, Var_Value);
Console.WriteLine("Value stored in environment variable");
}
else
{
Console.WriteLine("Value already stored in environment variable");
}
}
}
Output:
Value stored in environment variable
Press any key to continue . . .
Program:
The source code to demonstrate the use of SetEnvironmentVariable() method of Environment class is given below. The given program is compiled and executed successfully.
Output: