19
Sep

What is Debug directive in c# ? c# and .NET interview question


In this video will try to understand what exactly is the use of debug directive Many times you want some of the code to only run while you are debugging But we do not want those code to shift to production server or you do not want those code to run while you go live To understand the debug directive I have very simple sample code here and let say that while I am debugging this sample code I would always like to go and see the current version number of my operating system probably every time this program starts As a developer for some reason I want this operating system version to be seen while I run this program This code I do not want to shift in production This code is only meant is only meant for development When I run this application using this debug mode here As soon as I go and use this release mode to go live I don’t want this line of code to run I don’t want my end users go and see the operating system version this is meant only for me when I do the development How to ensure when we go and switched to the release mode. This code is not shift to the production server For that we have something called as the debug directive In order to use the debug directive the way we write the code is we have to say here # if the compilation is in a debug mode We end this if with a #endif If our compilation or if our application is running in a debug mode then run this code But we do not want this code to shift while we doing production If I run this application using debug mode I should be able to see the version number Currently I can see this version number If I compile this program In the release mode here If I run this application Its not displaying the operating system version If you want to cross check if ever this code get shift into the release mode Go to the folders of this console application In bin directory we have two folders one is Debug folder which has the exe which is meant to be used only in development environment and one is a Release folder which has a exe which should be used only in production environment To check if that code actually displays a version number of the operating system version number has been shifted in the release mode or not Go to the Visual Studio command prompt Open the ildasm tool First open the debug code If you open the debug IL code you can see he is using this operating system object here and he is using get _OSVersion () to display the version number If I now open the release.exe There is no code which is pertaining to the operating system Whatever is inside this if debug will not be shift when you will compile your Project in a release mode You want some code to run in development environment. You do not want those code to shift in your production environment Do not forget to use if debug directive I hope you enjoyed this video In this video we were trying to understand what is the use of Debug directive and how does it help us during development and go live Whatever video you have seen is just a glimpse of what we have done In case you are interested in our video package go to our site i.e www.questpond.com You can call on this number and ask the complete dvd package what we have In this dvd package we have covered almost everything what a .NET developer wants Right from basics of ASP.NET, Object Oriented Programming, SQL Server to new technologies like WCF, Silverlight, LINQ, Azure, Entity Framework We also have UML, Architecture, Estimation Project Management There is a complete invoicing project end to end which is covered you can get a better feel of How to create projects in a systematic manner We have covered server products both for Sharepoint 2007 as well as 2010 We have lot of best practices video on SQL server etc This complete package you can get from www.questpond.com In the same way as compare to the videos we also have one more product with us i.e Our Interview Questions Book. We have different kinds of interview question books right from .NET Interview questions to SQL Server Interview Questions Sharepoint Interview Questions, BizTalk Interview Questions etc If you are interested in the books part you can call on these numbers as per your location Keep enjoying the videos, keep seeing our site and I hope you gain more knowledge Thank you very much

Tags: , , , , , , , , , ,

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *