Example

using System;
using System.Security;
using System.Security.Permissions;

[assembly:EnvironmentPermissionAttribute(
                SecurityAction.RequestMinimum,
                Read="COMPUTERNAME;USERNAME")]

namespace Samples
{
  public class SecurityActionSample
  {
    public static void Main()
    {
      string[] v = {"USERNAME", "COMPUTERNAME"};
      foreach(string s in v)
        Console.WriteLine("Variable {0} Value: {1}",
                 s,
                 Environment.GetEnvironmentVariable(s));

    }
  }
}
The output is
Variable USERNAME Value: damien
Variable COMPUTERNAME Value: PROJECT42

Get .NET Framework Standard Library Annotated Reference, Volume 1: Base Class Library and Extended Numerics Library now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.