Search code examples
c#visual-studiohotkeysstring.formatconsole.writeline

How can I type "{0}" more quickly in Visual Studio?


In C#, it's common to have to type {0}, {1}, etc. when formatting strings with string.Format() or Console.WriteLine(). Considering its frequency, it's an awkward set of key strokes. But despite my searches, I couldn't find any sort of shorthand or hotkey to automatically insert it in Visual Studio. Has anyone figured out something to expedite the process?


Solution

  • You can create the following command (C#) with my Visual Commander extension to insert text and then assign a keyboard shortcut to it:

        EnvDTE.TextSelection ts = DTE.ActiveDocument.Selection as EnvDTE.TextSelection;
        ts.Text = "{0}";