How can I format my C# code so it displays correctly in our internal Wiki?

We are using MediaWiki although I assume most wiki syntax is the same.

  • Formatting the C# code that way will make that C# code not compilable. Is this OK?
    – m0skit0
    Oct 26 '11 at 8:58

If you are using the GeShi syntax highlighting extension to MediaWiki, then you can just insert your C♯ code as-is, enclosed within a <syntaxhighlight/> element. (This is, as you can see from the syntax highlighting extensions category, one of several such MediaWiki extensions.)

The MediaWiki wikis used, by the Wikimedia Foundation, for Wikipedia, Wiktionary, Wikibooks, Wikiquote, et al. all have this extension enabled. Here is some wikitext taken directly from the current (at the time of writing) Wikipedia article for C♯ (q.v.) that exemplifies what the wikitext looks like:

<syntaxhighlight lang=CSharp>
// Declare the generic class.

public class GenericList<T>
    void Add(T input) { }

class TestGenericList
    private class ExampleClass { }
    static void Main()
        // Declare a list of type int.
        GenericList<int> list1 = new GenericList<int>();

        // Declare a list of type string.
        GenericList<string> list2 = new GenericList<string>();

        // Declare a list of type ExampleClass.
        GenericList<ExampleClass> list3 = new GenericList<ExampleClass>();

See the Wikipedia article for how this wikitext is rendered.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.