This is probably the first of a number of posts I'll be writing about uses for C#'s Extension Method capabilities.
The code below will add a Groovy-like execute() method to the String class of .NET.
// the container is a static class and the method uses the 'this' keyword within the first parameter. // the additional method will be bolted on to the type listed in the first parameter after the 'this'. publicstaticclass GroovyLike { publicstaticvoid Execute(thisstring s) { System.Diagnostics.Process.Start(s); } }
//and then using it publicclass Util { publicvoid LaunchExcel() { "excel.exe".Execute(); } }