Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can use the Environment class in .NET to access and modify environmental variables created by the user. The Environment class provides a method called SetEnvironmentVariable() to modify an environmental variable and a method called GetEnvironmentVariable() to access the value of an environmental variable.

Here's an example of how to modify an environmental variable called "MYVAR" in a C# console application:

string myVarValue = "mynewvalue"; // the new value you want to set
Environment.SetEnvironmentVariable("MYVAR", myVarValue);

And here's an example of how to access the value of an environmental variable called "MYVAR" in the same C# console application:

string myVarValue = Environment.GetEnvironmentVariable("MYVAR");