.NET
  Home arrow .NET arrow Page 2 - Knowing Your Environment: the System.Envir...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
.NET

Knowing Your Environment: the System.Environment Class
By: Ayad Boudiab
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2008-05-12

    Table of Contents:
  • Knowing Your Environment: the System.Environment Class
  • More Properties
  • More Explanations
  • Methods

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Knowing Your Environment: the System.Environment Class - More Properties


    (Page 2 of 4 )


    CurrentDirectory : This property gets or sets the fully qualified path of the current working directory. Keep in mind that the current directory will contain a trailing slash if the process starts in the root directory. Otherwise, there will be no trailing slash. To print the current directory, use the following statement:


    //returns a string containing a directory path

    Console .WriteLine( "The directory path is: " + Environment .CurrentDirectory);


    ExitCode : The result of this property is a 32-bit signed integer that contains the exit code of the process. Why would I need the exit code of the process? Glad you asked. The Main() method is the entry and exit points of an application. There are multiple versions of the Main() method. Our concern, however, is with the return type. Main() can return a void or an int. The int value reports to the calling program (probably a script) the status information. A 0 means that the program ran successfully. Other values means there are errors. However, how would you know the status when Main() returns void? The answer is: ExitCode. Just use the ExitCode property to get or set the exit code of the process:


    //returns 0 by default, which means success!

    Console .WriteLine( "The ExitCode is: " + Environment .ExitCode);


    HasShutdownStartedThis property returns a Boolean value (true/false) to indicate whether the common language runtime is shutting down or the current application domain is unloading (in .NET, assemblies are not hosted directly in a process. They are hosted in an application domain). Use this property in an object's finalization method. If it returns true, then you cannot reliably access any object that has a finalization method and is referenced by a static field.  

    //returns a boolean value that indicates whether the common language runtime

    //is shutting down or the application domain is unloading

    Console .WriteLine( "Has shutdown started? {0}" ,

      E nvironment .HasShutdownStarted);


    MachineName: This property returns a string containing the name of the computer.


    //returns a string containing the name of this computer

    Console .WriteLine( "MachineName: {0}" , Environment .MachineName);


    NewLineUsing this property results in a new line inserted in the string. You can use n, but in some platforms you might need rn. To be on the safe side, use Environment.NewLine consistently.


    //A string containing "rn" for non-Unix platforms,

    //or a string containing "n" for Unix platforms.

    Console .WriteLine( "Line 1{0}Line 2" , Environment .NewLine);


    OSVersionThis property gets an OperatingSystem object that contains the current platform identifier and version number. Knowing the operating system version on which your application is running is extremely important; it helps you take advantage of some of the functionalities that exist in one version of the OS and not in another.


    //Gets an OperatingSystem object that contains the current platform //identifier and version number.

    Console .WriteLine( "OS Version: {0}" , Environment .OSVersion.ToString());


    ProcessorCount: Knowing the number of processors on the machine will help you take advantage of multiprocessing. This property will help you discover that value.


    //Gets the number of processors on the current machine.

    Console .WriteLine( "The number of processors on this computer is {0}." ,

    Environment .ProcessorCount);

    More .NET Articles
    More By Ayad Boudiab


       · Hello everyone,Here is my latest article on the System.Environment class.Please...
     

    .NET ARTICLES

    - Using CrystalReportViewer to Display Crystal...
    - Creating Summary .Net Crystal Reports
    - More on Commands, Input and the WPF
    - Grouping and Aggregating When Querying LINQ ...
    - Commands, Input and the WPF
    - Keyboard and Ink Input with WPF
    - Mouse Input and the WPF
    - Input with Windows Presentation Foundation
    - Introducing LINQ with XML and Databases
    - An Introduction to LINQ
    - Querying LINQ to SQL: Basics
    - Completing a Simple Storefront with LINQ
    - Knowing Your Environment: the System.Environ...
    - Creating the Home Page for a Simple Storefro...
    - LINQ Quickly with Language Integrated Queries





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT