How do I get the following to show up (on stackoverflow) with color syntax highlighting?
class Foo { internal Foo() { for (int i = 0; i < 42; ++i); } }
Meta Stack Exchange is a question and answer site for meta-discussion of the Stack Exchange family of Q&A websites. It only takes a minute to sign up.
Sign up to join this communitySee https://stackoverflow.com/editing-help.
Basically, for code, indent four spaces -- you can do this by pasting code then highlighting and hitting Ctrl + K or the {}
button above the editing box.
As far as syntax highlighting, see Changes to syntax highlighting and Interface options for specifying language prettify.
The correct language will often be inferred by the tags on the question, but you can manually specify it with an HTML comment:
<!-- language: c# -->
public static bool IsAwesome { get { return true; } }
or
<!-- language: lang-js -->
setTimeout(function () { alert("JavaScript"); }, 1000);
before the code block.
code highlight stackexchange
, and this is the first result.
If you want to insert code inline like this int i = 0;
use backticks: `int i = 0;`
. If you want an entire block of code you can highlight it and then click the code button which looks like {}
. You can also hit Ctrl+K
while it's highlight, or just manually indent it all 4 spaces:
class Foo { internal Foo() { for (int i = 0; i < 42; ++i); } }