简体   繁体   中英

Is there a keyboard shortcut for Visual Studio to invoke the class constructor for a new object?

I'd like a way to quickly instantiate a new object in C# using Visual Studio when defining an object variable. Lets say I type the following code

Object someObject =

Is there a way to auto-complete the line of code with a one or two keystroke combination to achieve the code below?

Object someObject = new Object();

Currently I end up auto-completing the new keyword, then auto-completing object class, and then tabbing outside of the auto-generated parenthesis and typing the semi-colon. I know this is probably minimal already(six keystrokes?), but I'd love a way to auto-complete these statements more intelligently that IntelliSense already does.

To answer the question in the title, this is really simple to do. There's no keyboard shortcut but you can type ctor then hit tab twice.

I think what you wanted to ask was "Is there a quick 'IntelliSense' way to declare and instantiate an object?"

The answer to this is yeah, type it out and use IntelliSense!

Just as @Rufus L says, the quickest way to do this is by using IntelliSense the way you could. In your example if you typed 'ne' then tab, you'd likely get the new keyword, then begin typing 'Obj', then tab again and IntelliSense will know the type your after based on what you've already typed and whack it in for you.

For this example, IntelliSense isn't really showing off its great capabilities. You'll learn to use IntelliSense to speed all sorts of things up pretty quickly and it's a neat helper for us developers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM