Retrieve the Value of an Environment Variable - CSharp System

CSharp examples for System:Environment

Description

Retrieve the Value of an Environment Variable

Demo Code


using System;//from  ww  w.j  a v  a  2 s  .c om
using System.Collections;

class MainClass
    {
        public static void Main()
        {
            Console.WriteLine("Path = " + Environment.GetEnvironmentVariable("Path"));
            Console.WriteLine(Environment.NewLine);

            Console.WriteLine(Environment.ExpandEnvironmentVariables("The Path on %computername% is %Path%"));
            Console.WriteLine(Environment.NewLine);

            IDictionary vars = Environment.GetEnvironmentVariables( EnvironmentVariableTarget.Process);

            foreach (string s in vars.Keys)
            {
                if (s.ToUpper().StartsWith("U"))
                {
                    Console.WriteLine(s + " = " + vars[s]);
                }
            }
        }
    }

Result


Related Tutorials