How do I stop Visual Studio from inserting “object” when I type “new {”

浪尽此生 提交于 2019-11-29 01:32:50

You can configure which characters being typed commit the current intellisense selection. In Tools | Options | Text Editor | C# | IntelliSense.

Remove "{" and ensure committed by the space bar is not checked.

NB. This option is no longer present as of Visual Studio 2015.

I ran into this issue, and the answers above didn't work for me. In my case, it was caused by Resharper, and I addressed it by navigating to Resharper -> Options -> Environment -> Intellisense -> Completing Characters and adding the opening curly brace character "{" to the "Do not complete on" list for C#.

What are you typing before the new {?

I've just tried it and it auto-completes with the object type, so if I type:

Button test = new { 

it becomes:

Button test = new Button{

But if I type:

var test = new {

it leaves it alone.

I haven't configured my VS2008 install in any way.

Have you checked your auto-complete options for ReSharper? I just tried this in a new (empty) class with the default ReSharper settings and couldn't duplicate it. What version of studio/ReSharper are you using?

Try typing the left brace first, then going back and typing new. VS2008 does this for me (without ReSharper) and, if I remember, this is what I do. It's less typing than deleting the inserted "object".

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