Extension method: Difference between revisions

Content deleted Content added
Line 17:
string y = x.Reverse();
 
==Extension Methodsmethods==
The new language feature of extension methods in C# 3.0, however, makes the latter code possible. This approach requires a static class and a static method, as follows:
in C# 3.0 you can configure the Util.Reverse() function to make the first code doable, so consider the following code of Util.
 
public static class Util
Line 32:
}
}
 
as you can see it is a simple static class, with one static function called Reverse, all what we have to do
 
# Make sure that the class is static
# Add this keyword before the type of the argument you want to extend.
 
so now you can write this code,
 
string x = "some string value";
string y = x.Reverse()
 
==Related==