One of my favorite Visual Studio Shortcut- Very useful !

“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.

1

Fig: Use Right Click To Add Namespaces

But using “Ctrl+.” you can automatically add the using statement . See the below Image.

2

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

3

Fig : Create Method stubs using  “Ctrl + .”

4

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.

5

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.

6

Fig: Implement Interface

7

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.

9

Fig: Generate new class/interface using shortcut key

8

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.

10

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 !

AJ
Shout it

16 thoughts on “One of my favorite Visual Studio Shortcut- Very useful !

  1. 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

  2. […] 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&#039 ;); }); } 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&#039 ;); }); } 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 […]

  3. 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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s