
Sometimes, while working, we face some silly problems that are very easy to solve by nature, but we can’t figure them out at that moment and waste some valuable time finding solutions. Similar happens to some other scenario, where we knew what to do to get a certain result but can’t memorize particularly. I was thinking of making a list of these small things in my blog, which might be helpful for myself and maybe to other audiences(I hope :)). I am planning to create different articles for different types of development environments. Today, I will explain some very quick/small .NET tips and tricks for a visual studio environment. I usually use Visual Studio 2010.
Show Line Numbers On VS Editor:
I still remember when, at the very beginning of my familiarity with Visual Studio, I often forgot how to show the line number on my code editor. By default, it isn’t enabled by Visual Studio. But it’s somehow very important to remember it in a long file of code. You will have to go to “Tools->Options->Text Editor->All Language->General” and check the box titled ‘Line numbers’ under the ‘Display’ section. See the image below for a more accurate idea:
If you need to do this for a specific programming language, you can do so as well. Just find this similar settings under that specific programming language(like c#), instead of ‘general’.
Using ‘Region’ And ‘If’ Directives:
Did you know we can use this directive in various useful scenarios to keep our code manageable and easy to debug? These can be used in any programming language that .NET supports. There are a few more directives, though; these two seem very useful to me. These directives are used anywhere in the code file and start/end with a ‘#’ character. Please check here to see more details about the directives.
Using the region block, you can combine the related properties/methods/code block in a single collapsible/expandable section. In this way, if you use it through the file, even a long coded file also becomes easy to traverse. Here is a simple example of how to write this:
#region All code related flying
//all codes go here
#endregion
#region All code about eating
//codes go here
#endregion
Code language: PHP (php)
notice the above image, no matter how long the class is, if you organize that is some such regions, you will find more comfortable to work with them time to time. Finding a code block also becomes super easy.
in the similar way, the ‘if’ directive helps you to create some extra code segments of code for a particular condition. Suppose, you need to execute some code in debug mode, but not in release mode. Here this directive will be very helpful.
#if DEBUG
//debug code goes here
#endif
Code language: PHP (php)
Another interesting thing here is, this will show you whether the code block is currently active or not. Such as, if you are in debug mode and using code like above, the inner codes will be normal like other codes. But, if you change settings to release mode, this code block will become gray, like commented code, mentioning this won’t be executed in current settings.
Downgrade Projects From Visual Studio 2010 To Visual Studio 2008:
This is a scenario when you may not have an updated Visual Studio on your PC but need to open the solution(s)/project(s) created on the updated version. Luckily, downgrading Visual Studio 2010 to Visual Studio 2008 is pretty straightforward and/or easy. Open your solution file(with .sln extension) in Notepad or a similar editor, find the Visual Studio version at the top of the file, which should be ‘11.0’ and change that to ’10’. Also, change the ‘visual studio 2010’ to ‘visual studio 2008’ also. And you are done. The solution and related projects will now be easily opened in Visual Studio 2008. This worked for me very well, without any issues. If you are having any issues while doing this, let me know the details via commenting. I will try to find a solution as soon as possible and refine this section.
For your information, I will be extending this article day to day to add other related tips as well. So, if you have any similar .net tips and tricks in mind, please let me know by commenting on this article or via contact page. I will try to attend them and integrate on this article as soon as I can. Happy coding 🙂 .
Discover more from CODESAMPLEZ.COM
Subscribe to get the latest posts sent to your email.
Leave a Reply