Environment variables are a universal mechanism for conveying configuration information to programs. Let’s look at how to set, get, and list environment variables in C#.
Running the program shows that we pick up the value for FOO that we set in the program, but that BAR is null.
The list of keys in the environment will depend on your particular machine.
If we set BAR in the environment first, the running program picks that value up. In C#, you can set environment variables before running the program using the command prompt:
Note that the exact method of setting environment variables may vary depending on your operating system and how you’re running the C# program.