52

Suppose I have a partial class in my application.

Let's say I have one part of this class open in Visual Studio and I want to find the other parts. How can I do this? Is there a keyboard shortcut or any other method that I can use to quickly navigate to the other parts of my class?

This would be useful because in a large application, there are so many individual *.cs files that manually searching for partial classes gets very inefficient.

Mage Xy
  • 1,803
  • 30
  • 36
Pritesh
  • 3,208
  • 9
  • 51
  • 70

2 Answers2

57

If you open the context menu on the class name and click "Go To Definition (F12)", then the panel "Find Symbol Results" will show at the bottom (by default) of Visual Studio. Here you'll find all (partial) definitions of that class.

partial class

Community
  • 1
  • 1
CodeCaster
  • 147,647
  • 23
  • 218
  • 272
  • 3
    thanks for answering.... actually i am confused because i have one application download from NET which has a class define as partial class but though it don't have another part it only have one part though it is partial class... – Pritesh Oct 12 '11 at 10:19
  • 3
    A partial class can exist of **one or more** parts. So it's possible that you only find one definition. If that is the case, then the panel in the screenshot above won't show when you go to the definition of the class. – CodeCaster Oct 12 '11 at 11:04
  • 4
    ya...exactly...if there exist only one part of partial class then..... **go to definition** will not show the above window.......Thank you so much for the answering again.... – Pritesh Oct 12 '11 at 11:30
  • 2
    2 partial classes = 2 results, 3 partial classes = 3 results, 4 partial classes = 4 results, so n partial classes = n results? No silly. 1 partial class = 0 results. Crazy thing is someone spend additional coding time making the response more ambiguous. "If there is only one partial class we should show nothing because obviously that is less ambiguous than just showing the single result which we already have in order to know there is only one". – Gerald Davis May 13 '15 at 16:02
  • 1
    @Gerald "go to definition" predates partial classes, which were introduced in C# 2. The "partial window" was added later, and obviously when there is only one definition of a class, "Go to Definition" should directly go there. – CodeCaster May 13 '15 at 18:02
  • 1
    Source generators like RegexGenerator can create partial classes that a hidden. – Olivier Jacot-Descombes Aug 12 '23 at 12:02
10

In my case (Visual Studio 2013 and also Visual Studio 2015) the solution CodeCaster describes did not work for me - Find Symbol Results doesn't show up as described in the answer.

But I found 2 other ways to solve it, which work for me. Do the following:


Solution 1
Tested with Visual Studio 2013/2015, Visual Studio 2017 and Visual Studio 2019

  1. Right-click and select "Go to definition". This will open up one of the (possibly many, but in most cases two) parts of the class.
  2. Put the cursor on the class name to mark it, i.e.
    public partial classMyClass
  3. Press F12. A "declarations" window will open. Click into it to give it the focus. Partial

  4. Press F8 to navigate to the next, or SHIFT+F8 to navigate to the previous declaration (or click on the previous/next buttons with the mouse).

Note: Only if there is more than 1 partial class, you will see the file names where the parts of the class are found:


Solution 2
Tested with Visual Studio 2017

  1. Put the cursor on the class name to mark it, i.e.
    public partial classMyClass
  2. Press ALT+SHIFT+F12. This will search the symbol selected in the entire solution.
  3. All occurances of the class are listed in the Find Symbol Results window.

The disadvantage of Solution 2 is that the references are listed as well, not only the partial classes.


Updated Answer for newer versions of Visual Studio (2019).

Matt
  • 25,467
  • 18
  • 120
  • 187
  • Find Symbol Results (this is the name of the window not the name of the command). Still exists in VS2013. It is possible you have hidden this window in which case it will not appear. View > Find Results > Find Symbol Result to make it non-hidden again. – Gerald Davis May 11 '15 at 15:39
  • @Gerald: Thank you for the hint, it is good to know from where that window can be opened. In my case that did not help, maybe because I am using **[ReSharper](https://www.jetbrains.com/resharper/)** (if you're using the context menu "Go to declaration" then the Find Symbol Results window remains empty). – Matt May 13 '15 at 08:35