Skip to main content

Explore the Use of System.Environment Class

System.Environment class can not be inherited. It provides valuable information about current platform and environment of the system.
It uses to retrieve environment variable settings, version of the CLR and call stack contents etc.

It has various methods and property to get the useful information about current working environment. Lets have a look on some of most used properties.

Get the Machine Name
– To Get the current system’s machine name we can use MachineName property of Environment class.

For example :
Console.WriteLine(“Machine Name :” + Environment.MachineName);

Get the Current Working Directory
– To Get the current working directory we can use CurrentDirectory property of Environment class.

For example :
Console.WriteLine(“Current Directory :” + Environment.CurrentDirectory);

Get the Current UserName of the system
– To Get the current user name we can use UserName property of the Environment class.

For example :
Console.WriteLine(“User Name :” + Environment.UserName);
Get the current Operating System Version ?
– To Get teh current OS Version we can use OSVersion property of the Environment class.

For example :
Console.WriteLine(“OS Version :” + Environment.OSVersion);

See the below Full C# code.

using System;

namespace SystemEnv
    class Program
        static void Main(string[] args)
            Console.WriteLine("Line 1");
            Console.WriteLine("Line 2");
            Console.WriteLine("Machine Name :" + Environment.MachineName);
            Console.WriteLine("Current Directory :" + Environment.CurrentDirectory);
            Console.WriteLine("OS Version :" + Environment.OSVersion);
            Console.WriteLine("User Name :" + Environment.UserName);

What is the Difference between Build, Rebuild and Clean in Visual Studio?

If you are a Microsoft Asp.Net Developer then usually you came across this words like Build, Rebuild and Clean.

This article gives you explanation about Difference between Build, Rebuild and Clean

If you are using Visual studio you might have question that what is difference between Build, Rebuild and Clean ? here we are going to understand the diversity between them.

Build Solution :
When we build any solution then Visual studio will build/compile all assemblies (Dlls and EXE’s) that are changed, it is basically incremental or partial process in which only CHANGED assemblies are compiled if there is no changed assemblies it won’t get build

Rebuild Solution:
It is full compiled case, in which all assemblies (either changed or not) are deleted and recompiled again, irrespective of changed or not

Clean Solution:
It is not compile case, it just delete all assemblies (Dlls and EXE’s) from folder but not compiled them again, it remove all compiled files from previous build

Hope you understand this simple article

What are the Differences between the Debug class and Trace class?

Debug and Trace both classes are included in Systems.Diagnostics namespace and have very similar methods. The main difference is that call to Debug class is included in Debug mode only while call to Trace class will be included in Debug as well as Release mode also.

So in short we can say it is advisable to use Debug at the time of application development, while Trace option is used at the time of application deployment, like we can trace any error and write it into log files etc.

What is the differences between a Debug and Release build?

When we are building any .Net project there are two configuration we can select 1 is Debug and another is for Release, While we are developing an application default mode is Debug and programmers keeps is Debug mode for debugging code step by step or line by line. Once project is completed we need to change it to Release mode before generating final build like DLL, EXE or published code.

The Debug mode does not optimize the binary it produces because the relationship between source code and generated instructions is more complex. This allows breakpoints to be set accurately and allows a programmer to step through the code one line at a time. The Debug configuration of your program is compiled with full symbolic debug information which help the debugger figure out where it is in the source code.

Normally Debug builds are not optimized and it has debugging symbols, while the code build in the Release mode is more optimized, It is very less in size and more faster then Debug mode.

What is the role of .pdb files ?
PDB is stands for Program Database File, it contains the debug information about the application depending on the compiler option that we have used. It holds application state information and debugging information that allows incremental linking of a Debug configuration of out application. PDB file is created when we are running a C# application in Debug mode.

We can set the debug mode in web.config file as shown below

// For Debug mode

<compilation debug="true">


// For Release mode

<compilation debug="false">

Happy Debugging