c# environment variable testing

I’ve used AWS Secret Manager in the past, but no the free solution of environment variables. Super simple console test I did.

First you have to add your desired environment variable.
And then you could just enter the Env Var and get your results.
You MUST restart Visual Studio in order to reflect any updated environment variables, or you’ll find no output as the value will be null.

    internal class Program
    {
        static void Main(string[] args)
        {
            string GetKey(string key)
            {
                string keyRequest = Environment.GetEnvironmentVariable(key);
                return keyRequest;
            }

            Console.Write("Enter key name: ");
            string envVar = Console.ReadLine();

            Console.Write("The key value is: ");
            Console.WriteLine(GetKey(envVar));
            Console.ReadLine();
        }
    }

Leave a Reply

Your email address will not be published. Required fields are marked *