# Formatting C# code for wiki syntax

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.

-

## migrated from superuser.comOct 26 '11 at 20:07

This question came from our site for computer enthusiasts and power users.

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>
{
}

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>();
}
}
</syntaxhighlight>

See the Wikipedia article for how this wikitext is rendered.

-