Virtual Tech Days day one, session one. I delivered a talk titled "know your tools better". Firstly, thanks to all those who attended the talk. Thanks for having keeping patience inspite of the audio and video issues we faced. Due to lack of time i could not cover some things that i wanted to share and also could not take up questions. I had saved all the questions that were posted over live meeting and i will address them in this post.
Q1) How do extension method really work? Please show an example on using Extension methods
Extension methods are defined as static methods inside a static class. When the compiler comes across a call to Extension Method, it replaces the calls with corresponding instance method invocation of the static class.
Some facts about extension methods:
- Extension methods have lower precedence than instance methods. i.e if there is an extension method with the same signature as an instance method - it will be ignored by the compiler.
- Extension methods need to be defined in a non-nested static class
- The first parameter of the extension method starts with a keyword this which defines that this extension method will be applied to the type that immediately follows this keyboard.
- Extension methods cannot access private members of the class
Q2) What is a partial class
Partial classes allow you to divide the code of a single class into multiple files. You can define them using the keyword 'partial'. You can apply the partial keyword to a class, struct or interface.
Q) If there is any unused "Using System.Linq" in the code, will this affect the performance of the application or any drawback or so.
A) No. the compiler knows how to optimize and remove all unused references from the code during compilation - so there will be no runtime impact.
Q) I think the shortcut for inserting snippet is present in VS 2005
Q) ctrl + d combination is not working. will i have to enable anything ?
A) Should work. You don't have to enable anything. When you press ctrl +d in visual studio - it should take the cursor highlight into the find box. You can notice it being highlighted.
Q) Where to get these Code Analysis results?
A) right click on the project. You should see a 'run code analysis' option (5th in my case). Click on that. To see the results goto the Error List (you can enable it from the view menu or ctrl+\, ctrl+e). There you will see all the code analysis warnings (in CAXXXX format where XXXX is the error code). These warning give a lot of information about potential loop holes in the code. To get more information/help on each of these errors, what it means and how to resolve, select it and press F1.
Q) Run code analysis will be available for C#?
Q) Is the Run Code Analysis menu option available in VS2008 or do we need to install VSTS for the same?
A) Unfortunately, Code analysis is not available with professional edition. You will need VSTS for it. Alternatively, you can use FxCop which is a free utility from Microsoft to do a similar analysis separately. You can download FxCop from http://www.microsoft.com/downloads/details.aspx?FamilyID=9aeaa970-f281-4fb0-aba1-d59d7ed09772&DisplayLang=en
Q) What is a formula to calculate maintainability Index for whole Project?
A) you can get detailed information about the maintainability index at: http://blogs.msdn.com/fxcop/archive/2007/11/20/maintainability-index-range-and-meaning.aspx
Q) Can we set the build configuration at the solution level
A) Yes. When you open the Configuration Manager - you will see all the projects in the solution listed there. You can set the build for each of these separately.
Q) what was the command that you ran now in the immediate window?
A) You can get more details about what you can do in the immediate window here: http://msdn.microsoft.com/en-us/library/f177hahy.aspx
- During the demo i had loaded the sos extension dll from the immediate window by typing ".load sos" and run commands from it which help you to debug managed applications. You can get more details here: http://msdn.microsoft.com/en-us/library/bb190764.aspx
Q) Can you copy the short cuts Poster url in the QA Pane
A) C# key board reference poster : http://www.microsoft.com/downloads/details.aspx?FamilyID=c15d210d-a926-46a8-a586-31f8a2e576fe&DisplayLang=en
VB key board reference poster: http://www.microsoft.com/downloads/details.aspx?FamilyID=6bb41456-9378-4746-b502-b4c5f7182203&DisplayLang=en
Q) What is the difference between "Build" and "Rebuild"?
A) When you choose "Build", Visual Studio only compiles and links the portions of the assemblies that were affected by the changes since the last build. "Rebuild" - recompiles and links the complete project/solution again. "Rebuilds" can take more time for big projects.
Q) Why there are pdb files for a release mode build?
A) A lot of times there are issues that may happen only in the release build (e.g. due to optimizations or link sequence etc.) and may never happen in debug builds. So after an application is deployed and there are issues with it that do not happen in debug builds or cannot be reproduced on any other machine, there may be a need to debug the release build or debug on the production machine. In such cases symbols for the release build are very helpful. You may however not distribute symbols of the release build to the customer and just keep them in the repository for your debugging purposes.
Q) What are the symbols in the debug and release?
A) Symbols are usually stored in pdb files. They contain information about variable names, source file lines etc which are very helpful for debugging. You can create symbols for debug and release build both.
Q) Are these editor functionality available for XAML also?
A) A lot of the functions are available in the XAML editor also (see the edit menu). Also check out the features that specifically apply to XAML (Edit->Advanced, Edit->Outlining. Even ctrl+d, clip board ring (ctrl+shit+v) and most of the other short cuts that do not apply to code particularly work in XAML editor.
Q) I want to know more about the .Net tools
A) This is one thing i could not delve upon during the VTD. I had planned to talk briefly about (and other stuff if i got time):
Q) How can we clear the buffer for ctrl+c?
A) don't know. I tried to find - but could not.
Q) How do I access the registry from code on Vista? Since each time it tells me access denied.
A) Check out this wonderful link: http://www.microsoft.com/downloads/details.aspx?FamilyID=BA73B169-A648-49AF-BC5E-A2EEBB74C16B&displaylang=en
Hope i have been able to address your questions. Please let me know if i missed any question or if you have follow up questions.