Q:

C# program to demonstrate the use of SetEnvironmentVariable() method of Environment class

belongs to collection: C# Environment Class Programs

0
  • Syntax:

    void Environment.SetEnvironmentVariable(string var, string val);
    

    Parameter(s):

    • var: Environment variable name
    • val: Value that we store into a variable

    Return value:

    It does not return any value.

    Exception(s):

    • System.Security.SecurityException
    • System.ArgumentNullException
    • System.ArgumentException
    •  

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

The source code to demonstrate the use of SetEnvironmentVariable() method of Environment class is given below. The given program is compiled and executed successfully.

using System;
using System.IO;

class Sample
{
    //Entry point of Program
    static public void Main()
    {
        string Var_Name = "VAR1";
        string Var_Value = "True";

        if (Environment.GetEnvironmentVariable(Var_Name) == null)
        {
            Environment.SetEnvironmentVariable(Var_Name, Var_Value);
            Console.WriteLine("Value stored in environment variable");
        }
        else
        {
            Console.WriteLine("Value already stored in environment variable");
        }
    }
}

Output:

Value stored in environment variable
Press any key to continue . . .

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# Environment Class Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
<< C# program to demonstrate the use of GetEnvironmen...