A dictionary that contains all environment variable names and their values; otherwise, an empty dictionary if no environment variables are found.
Type Reason System.Security.SecurityException The caller does not have the required permission.
The names and values for the environment variables are stored as key-value pairs in the returned IDictionary.
Type | Reason |
---|---|
System.Security.Permissions.EnvironmentPermission | Requires permission to read environment variables. See System.Security.Permissions.EnvironmentPermissionAccess.Read. |
The following example prints the names and values of all environment variables defined in the environment.
C# Example
using System; using System.Collections; class EnvTest:Object { public static void Main() { Console.WriteLine("Environment Variables"); IDictionary envars = Environment.GetEnvironmentVariables(); IDictionaryEnumerator varEnumerator = envars.GetEnumerator(); while(varEnumerator.MoveNext() != false) { Console.WriteLine("{0}={1}", varEnumerator.Key, varEnumerator.Value); } } }
The output will vary depending on your system.