One of my favorite Visual Studio Shortcut- Very useful ! August 9, 2010
Posted by Abhijit Jana in General, Tips and Tricks, Visual Studio, Visual Studio 2010.Tags: Automatic Interface Implementation, codeproject, Shortcut Key, Tips and Tricks, Visual Studio 2010, VS Useful Shortcut Key
trackback
“Ctrl + .” Or “ALT + SHIFT+F10” is one of my favorite shortcut in Visual Studio. You can use the same shortcut for various situations as described in below.
1. Adding Namespaces Automatically / Resolve Namespaces.
2. Generate Method Stubs.
3. Implement Interface/ Abstract Class
4. Generate Automatic Class Files
5. Rename Member variables or Classes
Let’s start with one by one .
1. Adding Namespaces Automatically / Resolve Namespaces.
If you are adding a new class in your code you may need to add the correspondence namespace. To do it, you may either manually type the Using Namespace or you just right click on the class name and select Resolve > Namespace. But using “Ctrl+.” you can automatically add the namespace in your code.
Lets consider you want to add DataTable in your code, so for that you right click on that class and select resolve to resolve the namespace.
Fig: Use Right Click To Add Namespaces
But using “Ctrl+.” you can automatically add the using statement . See the below Image.
Fig : Add namespace using Shortcut key.
2. Generate Method Stubs
You can also generate the methods stubs using the same shortcut key. Like, If you want to create method which will add to number, you can write like AddTwoNumber() and press “Ctrl+.” and Enter to generate the Stub for your methods automatically
Fig : Create Method stubs using “Ctrl + .”
Fig : Generated Stub for the methods
The most interesting point it will generate the stubs based on the type of argument we are giving. As shown in below picture for first arguments its generated integer and for second its generated string.
Fig: Generated stubs based on parameters
3. Implement Interface/ Abstract Class :
Like similar process that we have used for first two example you can implement all the Interface or Abstract class using the same shortcut.
As for example you have a Class called student which Implement Interface IStudentInfo, instated of manually implement all the properties or methods for the interface you can generate the interface stubs automatically.
Fig: Implement Interface
Fig: Implemented stubs for the interface
4. Generate Automatic Class Files
This is related with features 3. If you are trying to implement one Abstract Class or Interface which is not created, by using this shortcut key you can create the file automatically. You do not need any manual process to add the file. By using “Ctrl+.” and Enter a class files with the same name will be automatically added in App_Code Folder.
Fig: Generate new class/interface using shortcut key
Fig: Automatically Created Files in App_Code
5. Rename Member variables or Classes
By using the same key “Ctrl+.” you can also rename the same referenced variable at a time in all over the application.
Fig: Renaming all referenced variables at a time
Summary : I this blog post I have explained how you can use a single shortcut key “Ctrl+.” in different places of your development. Hope this will help you.
Cheers !










One of my favorite Visual Studio Shortcut- Very useful ! « Abhijit’s World of .NET…
Thank you for submitting this cool story – Trackback from DotNetShoutout…
[...] One of my favorite Visual Studio Shortcut- Very useful ! [...]
good post
[...] One of my favorite Visual Studio Shortcut- Very useful ! « Abhijit’s World of .NET Posted in .Net. Leave a Comment » [...]
I have a small question can we generate getter setter for member variable automatically in VS 2008?
Thanks very much for the great article!
I have used the shortcut for 2 years and recently I have lost information about it because I’ve changed Visual Studio.
Name of this shortcut is: View.ShowSmartTag
(I think the name for this shortcut is not obvious. So I had some difficulties to search it)
Regards
Bronek
[...] One of my favorite Visual Studio Shortcut- Very useful ! jQuery(document).ready(function($) { window.setTimeout('loadTwitter_199()',1000);window.setTimeout('loadFBLike_199()',1000); }); function loadTwitter_199(){ jQuery(document).ready(function($) { $('.dd-twitter-199').remove();$.getScript('http://platform.twitter.com/widgets.js'
; }); } function loadFBLike_199(){ jQuery(document).ready(function($) { $('.dd-fblike-199').remove();$('.DD_FBLIKE_AJAX_199').attr('width','50');$('.DD_FBLIKE_AJAX_199').attr('height','60');$('.DD_FBLIKE_AJAX_199').attr('src','http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fdailydotnettips.com%2F2011%2F01%2F01%2Fgenerate-method-stubs-using-shortcut-key-in-visual-studio%2F&layout=box_count&action=like&width=50&height=60&colorscheme=light'
; }); } div.rax_subscribe { width:60%; float:left; border:8px solid #EBEBEB; text-align:center; background-color:#F0F0F0; } div.rax-email-subscribe { background-color:#AEAEAE; padding:5px 8px; height:60px; } div.rax-email-subscribe span { color:#FFF; font-size:12px; } div.rax-email-subscribe input.rax-button { font-size:14px !important; padding:2px !important; *padding:0px; } div.rax-other-subscribe { margin:10px 5px; } div.rax-other-subscribe img { display:inline; } .clear { padding:0; margin:0; } .rax-credit { width:60%; text-align:right; } .rax-credit a { text-decoration:none; font-size:9px; color:#CCC; } .rax-credit a:hover { text-decoration:none; } Subscribe to Daily .NET Tips via Email [...]
[...] More details can be found [...]
its mine too
Excellent one. Very useful!
tanx
NOT WORKING IN MINE 2010 VERSION . SHOULD I NEEDTO INSTALL STYLECOP
It has nothing to do with Stylecop ! Check if the shortcut keyword is assigned to something else.
Hi Abhi,
Thanks for providing shortcuts. But, I am unable to automatically generate Interface or abstract class definitions using above shortcut..
Please let me know how to do it, as i have tried doing above steps.
Hi Shankar,
Maybe you should use these shortcuts to show Intellisense with names of code snippets and just choose expected one (ie. abstract class or interface).
Remember, first you should create snippet for interface and abstract class.
regards
Bronek
vry nice.. can u give example on properties using ctrl+.