<p>How is it possible to make prototype methods in C#.Net?</p>

<p>In JavaScript, I can do the following to create a trim method for the string object:</p>

<pre><code>String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g,"");
}
</code></pre>

<p>How can I go about doing this in C#.Net?</p>

You need to create an extension method, which requires .NET 3.5. The method needs to be static, in a static class. The first parameter of the method needs to be prefixed with "this" in the signature.
```
```
public static string MyMethod(this string input)
{
    // do things
}
```
```
You can then call it like
```
```
"asdfas".MyMethod();
```
```