C#/.NET How do I find the containing namespace fro

2019-06-16 20:35发布

I often find myself remembering the name of a class that I want to use, but not remembering the containing namespace. Apart from searching the web, i wonder if a good method exists for looking this up.

8条回答
Anthone
2楼-- · 2019-06-16 21:12

If you know the name of a class in .Net but have no idea what namespace it is in, it can be hard finding it, especially if you dont have a reference/using to the assembly containing it.

This is where the Object Browser (Ctrl+W,J) comes in handy.

Open it up, type in the name, it will give you all matches, either within your project/solution, or all of the .Net framework.

Edit:
As S.C. Madsen's comment points out, this also helps if you only remember PART of a class name, also if you only remember a method name but not the class.

查看更多
冷血范
3楼-- · 2019-06-16 21:21

I generally use the offline MSDN reader, with the left panel set to the Index tab.

Another option in Visual Studio is to type the name of the type as if you were declaring a variable, and then see what it suggests. If the name goes to a light blue colour (by default) then it's in one of the namespaces you're already importing - just hover over it to find out which. Otherwise, see what namespaces it offers to add using directives for.

查看更多
登录 后发表回答