For large code blocks, nhahtdh's answer works perfectly. For single lines of code, I use this trick:
- Start and end the line of code with the backtick (grave accent `), just as you would an in-line block of code: `string example = "Like this..." `
- Then highlight that line and hit Ctrl+K as usual.
This example shows that both solutions line up correctly:
List item
bool truth = true; // Using grave accents.
bool lies = false; // Using 8 space indentation. if (truth == lies) { Console.WriteLine("Congrats on your election!"); }
List item