Ask Your Question
1

In a VS solution (.sln), how can I access and modify environmental variables that are created by the user?

asked 2023-01-20 11:00:00 +0000

huitzilopochtli gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2021-10-01 09:00:00 +0000

woof gravatar image

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");
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-01-20 11:00:00 +0000

Seen: 10 times

Last updated: Oct 01 '21