Do you know about Reference Counter in #VisualStudio 2013?


If you have already installed and used Visual Studio 2013, you might already noticed that every class and method has “x references” marked on top of it, where ‘x’ is a counter. These are called as “Reference Counter” and provides you information about the uses.

 

It’s a new feature in Microsoft Visual Studio and will definitely help the developers to find out the referenced count easily. In this blog post, we will discuss about this in detail. Keep reading.

 

What’s new in Visual Studio 2013?

If you are new to Visual Studio 2013, you may want to check the below posts first:

 

Reference Counter

Visual Studio 2013 has a no. of new features and enhancements for the developers to make their work easy. One of them is “Synchronization of appearance, theme, settings etc. across all your devices” that you use and logged in with your Live ID credentials. Among other new enhancements, one is easy access to know how many places you used your class, methods etc. Let’s see it in a piece of demo code.

 

Let’s assume, we have a class called Demo and there is a static method (to demonstrate it easily) named Print(). By default you will see them marked with “0 references” at the top of each declaring line. This means, you did not yet use the class and the method. Have a look into the following example:

 

ZERO Reference of the method and class

 

Now call the Print() method of the class from Program class and you will immediately notice that the reference count automatically increased to one and showing as “1 reference”. This means, you used it in only one location. Have a look at it here:

 

ONE References of the method and class

 

Let’s call it again. You will notice that the count has again increased and now showing it as “2 references” on top of each declaring line. Here is how it will look in this case:

 

TWO References of the method and class

 

You can see in the above examples that reference count of both the class and method is increasing by one in each call of the method. This is because, we are using a static call of the method. If we had a normal method “Print()” and if we called it by creating a single instance of the class “Demo”, in that case, the reference count of the class and method would be different. For example, calling the Print() method two times in a single instance of Demo class would generate “1 reference” count for the class and “2 references” count for the method.

 

The settings for the reference counter is enable by default but in case you did not find the behaviour in your Visual Studio 2013 IDE, you can easily enable it by going to the options page. To enable/disable it, go to Tools –> Options and then navigate to Text Editor –>All Languages –> Code Information Indicators at the left pane of the dialog. In the right pane, you will find a parent check box labelled “Enable Code Information Indicators” and a child check box labelled “Show References”. To enable this reference counter in your code file, both of them needs to be checked. In case, you don’t want it, just uncheck the child check box labelled “Show References”.

 

How to enable Reference Indicator in the Code Information

 

This new feature/enhancement will definitely help the developers like you to easily check the total nos. of places the class or method has been used. Isn’t it? Say thanks to the Visual Studio developer team for such a nice feature.

 

Stay tuned to my blog to know more about the other new features in Visual Studio 2013. I am available in Twitter and Facebook, don’t forget to connect with me there and say a “Hi”. This blog post was composed targeting the preview version of the IDE and hence this might change a little in the final product of the Visual Studio 2013 edition, which is very rare.


If you have come this far, it means that you liked what you are reading. Why not reach little more and connect with me directly on Twitter , Facebook , Google+ and LinkedIn . I would love to hear your thoughts and opinions on my articles directly. Also, don't forget to share your views and/or feedback in the comment section below.

25 comments

  1. 1. Great article, I learned something new
    2. These days reading content is getting too time consuming
    A YouTube OR Channel9 video would have explained this in 2-3 minutes and saved 10-15 minutes of reading

    My 2 cents would be to have videos blogs rather than textual blog

    ReplyDelete
    Replies
    1. I feel video-tutorials as a waste of time... unless they are accompanying a written one.

      Delete
  2. Nice one... Will be very useful..

    ReplyDelete
  3. Nice Feature... Will be very useful..

    ReplyDelete
  4. seriously a very helpful feature....

    ReplyDelete
  5. Kunal I did that before, while I was building an extension in 2010 ide. But it will come handy for sure.

    Here is the link of the previous implementation.

    http://www.codeproject.com/Articles/55196/Code-InfoBox-Visual-Studio-Extension-VSX-2010

    :)

    ReplyDelete
    Replies
    1. Yea, I read it looooong back. You should have sell this concept to Microsoft. BTW, I am in love with Visual Studio 2013. It's the best IDE as of now.

      Delete
  6. Is this feature dropped or only available on Ultimate version of VS2013? I have Premium 2013, Update 2.

    ReplyDelete
  7. Thanks for the article. Just to mention that this feature works only with VS2013 Ultimate, not with Premium.

    ReplyDelete
  8. Hi,

    I am using vs 2013 update 4.
    I don't have this code reference on my editor and also does not exist on my Tools-> Options-> Text Editor -> All Languages -> Code Information Indicator (this item does not exist, I only have: General, Scroll Bars, Tabs)

    What do I need to do to get this?

    ReplyDelete
    Replies
    1. Yep ... it exist only in the VS2013 ULTIMATE

      Delete
  9. informative post. Thank you so much for this wonderful site

    ReplyDelete
  10. Hi
    i have recently installed VS2013 Community version and i cant find the reference counter anywhere in the VS options.. dose this feature exist in the community version?
    Thanks.

    ReplyDelete
  11. Great work..Thanks a lot for this one and i am impressed with the writing...Assignment writing service

    ReplyDelete
  12. does anyone have any idea why i don't have the show reference combo box?

    ReplyDelete
  13. i'm professional, i should have it

    ReplyDelete
  14. I am so glad to have a chance to read your wonderful article. I am looking forward to read more of your works and posts. Keep on sharing.

    ReplyDelete
  15. This comment has been removed by a blog administrator.

    ReplyDelete
  16. This comment has been removed by a blog administrator.

    ReplyDelete
  17. Thanks for sharing the info, keep up the good work going.... I really enjoyed exploring your site. good resource. 
    Research Paper Writing
    Dissertation Writing Service Term Paper Writing Service

    ReplyDelete
  18. This comment has been removed by a blog administrator.

    ReplyDelete
  19. I'm using 2013, and I want to add Reference Counter extension, NEED SUGGESTION PLEASE

    ReplyDelete
    Replies
    1. Hi Sampat,

      This is by default present in VS2013. Please refer the above post.

      Delete
  20. Do you know if there is a way to create / show a list (in a Pareto fashion) from most referenced to least? We are working on updating code from old standards to newer, and would like to prioritize on the object referenced the most.

    ReplyDelete


 
© 2008-2016 Kunal-Chowdhury.com - Microsoft Technology Blog for developers and consumers | Designed by Kunal Chowdhury
Back to top