---
title: "Working with Environment Class in C#"  
description: "Working with Environment Class in C#"  
author: "Anonymous User"  
published: 2013-06-12  
updated: 2013-06-12  
canonical: https://www.mindstick.com/forum/1056/working-with-environment-class-in-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 3 minutes  

---

# Working with Environment Class in C#

How Can I work with [System](https://www.mindstick.com/articles/23411/the-most-effective-method-to-find-the-perfect-small-business-phone-system-for-your-business) [Environment](https://yourviews.mindstick.com/view/308/need-to-create-a-supportive-work-environment-for-women) [Class in C#](https://www.mindstick.com/forum/160399/how-to-create-a-custom-generic-class-in-c-sharp-provide-an-example)?

## Replies

### Reply by Vijay Shukla

Hello Ben Reitman!\
Below I give you some line of code which is provide an example of Environment [Class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp) in C#: -

```
using System;using System.Collections;
class Sample{    public static void Main()    {        String str;        String nl = Environment.NewLine;
        //        Console.WriteLine();        Console.WriteLine("-- Environment members --");
        // Invoke this sample with an arbitrary set of command line arguments.        Console.WriteLine("CommandLine: {0}", Environment.CommandLine);
        String[] arguments = Environment.GetCommandLineArgs();        Console.WriteLine("GetCommandLineArgs: {0}", String.Join(", ", arguments));
        // <-- Keep this information secure! -->        Console.WriteLine("CurrentDirectory: {0}", Environment.CurrentDirectory);        Console.WriteLine("ExitCode: {0}", Environment.ExitCode);
        Console.WriteLine("HasShutdownStarted: {0}", Environment.HasShutdownStarted);
        // <-- Keep this information secure! -->        Console.WriteLine("MachineName: {0}", Environment.MachineName);
        Console.WriteLine("NewLine: {0} first line{0} second line{0} third line",                              Environment.NewLine);
        Console.WriteLine("OSVersion: {0}", Environment.OSVersion.ToString());        Console.WriteLine("StackTrace: '{0}'", Environment.StackTrace);
        // <-- Keep this information secure! -->        Console.WriteLine("SystemDirectory: {0}", Environment.SystemDirectory);        Console.WriteLine("TickCount: {0}", Environment.TickCount);
        // <-- Keep this information secure! -->        Console.WriteLine("UserDomainName: {0}", Environment.UserDomainName);        Console.WriteLine("UserInteractive: {0}", Environment.UserInteractive);
        // <-- Keep this information secure! -->        Console.WriteLine("UserName: {0}", Environment.UserName);
        Console.WriteLine("Version: {0}", Environment.Version.ToString());        Console.WriteLine("WorkingSet: {0}", Environment.WorkingSet);
        // No example for Exit(exitCode) because doing so would terminate this example.        // <-- Keep this information secure! -->
        String query = "My system drive is %SystemDrive% and my system root is %SystemRoot%";
        str = Environment.ExpandEnvironmentVariables(query);        Console.WriteLine("ExpandEnvironmentVariables: {0} {1}", nl, str);        Console.WriteLine("GetEnvironmentVariable: {0} My temporary directory is {1}.", nl,
                               Environment.GetEnvironmentVariable("TEMP"));
        Console.WriteLine("GetEnvironmentVariables: ");        IDictionary environmentVariables = Environment.GetEnvironmentVariables();        foreach (DictionaryEntry de in environmentVariables)        {            Console.WriteLine(" {0} = {1}", de.Key, de.Value);        }
        Console.WriteLine("GetFolderPath: {0}",                     Environment.GetFolderPath(Environment.SpecialFolder.System));        String[] drives = Environment.GetLogicalDrives();
        Console.WriteLine("GetLogicalDrives: {0}", String.Join(", ", drives));        Console.ReadKey();
    }
}
```

\
If you want to more knowledge then read this article


---

Original Source: https://www.mindstick.com/forum/1056/working-with-environment-class-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
