[英]How do I stop Visual Studio from inserting “object” when I type “new {”
When editing a C# source file, I type 编辑C#源文件时,我输入
new {
Visual Studio auto-corrects it to Visual Studio自动更正它
new object{
Is there a way to stop this behavior? 有没有办法阻止这种行为?
You can configure which characters being typed commit the current intellisense selection. 您可以配置要键入的字符提交当前智能感知选择。 In Tools | 在工具| Options | 选项| Text Editor | 文字编辑器| C# | C#| IntelliSense. 智能感知。
Remove "{" and ensure committed by the space bar is not checked. 删除“{”并确保未选中空格键提交的内容。
NB. NB。 This option is no longer present as of Visual Studio 2015. 从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#. 在我的情况下,它是由Resharper引起的,我通过导航到Resharper - >选项 - >环境 - >智能感知 - >完成字符并将开头大括号字符“{”添加到“不完整”列表来解决它对于C#。
What are you typing before the new {
? 你在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. 我没有以任何方式配置我的VS2008安装。
Have you checked your auto-complete options for ReSharper? 你有没有检查过ReSharper的自动完成选项? I just tried this in a new (empty) class with the default ReSharper settings and couldn't duplicate it. 我刚刚使用默认的ReSharper设置在一个新的(空)类中尝试了这个,并且无法复制它。 What version of studio/ReSharper are you using? 您使用的是什么版本的studio / ReSharper?
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. VS2008为我做了这个(没有ReSharper),如果我记得的话,这就是我的工作。 It's less typing than deleting the inserted "object". 它比删除插入的“对象”更少打字。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.