admin管理员组

文章数量:1122846

Let's take the example:

var myObject = GetCustomer(1234);

Where GetCustomer retrieves an object which is representative of a customer with the class myClass.

Is there a quick way in VS2022 to navigate to the declaration of myClass either through the mouse, keyboard or menu?

If I right-click on myObject, I get a number of items which pop up. I've tried "Go to Declaration", "Navigate To...", "Go to Definition", "Go to base", "Go to Implementation", none of them take me to where myObject is actually declared (not sure why "go to declaration" doesn't work, it takes me to the first time the variable is used in the current function).

As a bonus, I do have reSharper also installed, so perhaps a way to do it in there, but I don't see anything.

Let's take the example:

var myObject = GetCustomer(1234);

Where GetCustomer retrieves an object which is representative of a customer with the class myClass.

Is there a quick way in VS2022 to navigate to the declaration of myClass either through the mouse, keyboard or menu?

If I right-click on myObject, I get a number of items which pop up. I've tried "Go to Declaration", "Navigate To...", "Go to Definition", "Go to base", "Go to Implementation", none of them take me to where myObject is actually declared (not sure why "go to declaration" doesn't work, it takes me to the first time the variable is used in the current function).

As a bonus, I do have reSharper also installed, so perhaps a way to do it in there, but I don't see anything.

Share Improve this question edited Nov 21, 2024 at 17:57 marc_s 754k183 gold badges1.4k silver badges1.5k bronze badges asked Nov 21, 2024 at 17:30 LarryBudLarryBud 1,07312 silver badges23 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 1

If the return type of GetCustomer is myClass (so the type of myObject is also myClass), you can navigate to myClass using either of these options:

  • Hold Ctrl and click the var keyword.
  • Right-click the var keyword and click Go to Definition.

If GetCustomer might return a subclass of myClass, then you can right-click the var keyword and click Go to Implementation to see a list of subclasses of myClass.

本文标签: cIs there a quick way to navigate to the underlying object of a variable in Visual StudioStack Overflow