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

前端 未结 5 1779
轻奢々
轻奢々 2020-12-15 23:53

When editing a C# source file, I type

new {

Visual Studio auto-corrects it to

new object{

Is there a way

相关标签:
5条回答
  • 2020-12-15 23:58

    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".

    0 讨论(0)
  • 2020-12-16 00:01

    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?

    0 讨论(0)
  • 2020-12-16 00:03

    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#.

    0 讨论(0)
  • 2020-12-16 00:06

    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.

    0 讨论(0)
  • 2020-12-16 00:12

    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.

    0 讨论(0)
提交回复
热议问题