Can you enable Error Corrections for C# in Visual Studio?

﹥>﹥吖頭↗ 提交于 2019-12-11 10:24:16

问题


Visual Studio 2010 contains error corrections for VB programmers, for example, it will allow you to import a namespace or generate a stub class/method where you get compiler errors.

For example, if you type:

Dim mm As MailMessage without an Imports System.Net.Mail, you'll get a handy little tooltip that just allows you to import the namespace with a single click.

I've recently switched to C# developing, and I really miss this little tool - if you're not sure of a namespace you have to go looking on Google to find out and then add the using manually.

Is there no way to enable the error corrections like you get when writing VB?

I've done the usual Googling, and there seems to be no mention of it for C#- just VB.


回答1:


C# editor has that. Just click on the class name and you'll see a colored underscore. Click on it and you'll get suggestions on how to resolve class (or interface, or whatever).

Or put code editor cursor on the class name and press ALT + SHIFT + F10 and the same suggestions will popup for you.




回答2:


I use C# in VS2010 daily and it does all the things you mention. As an example, usually when you paste code into a class without the relevant using statements already being present VS will ask you if you want to add usings for the code you pasted. It is worth checking your settings to make sure you have things like this enabled such as 'Auto List Members' etc. There are other useful settings in there too. It is worth familiarising yourself with your options.

One thing I would recommend for C# development is Resharper 7. It is a great tool and speeds up coding an awful lot. It will also make suggestions to improve code, enforce standards etc. You can also configure it to enforce the coding standards your company uses. I believe you can get a trial version. I would get that to try it out and then if required make a purchase request to your company or buy it yourself. Its worth it.

Resharper 7

P.S. As a side note, in case you didn't know, you can press ctrl+spacebar to get your intellisense options to open up.



来源:https://stackoverflow.com/questions/12052116/can-you-enable-error-corrections-for-c-sharp-in-visual-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!