Sınıfın yapısını değiştirmeden sınıfa ek olarak yazılabilen fonksiyonlardır.
Extension methods enable you to “add” methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type. Extension methods are static methods, but they’re called as if they were instance methods on the extended type.
The following example shows an extension method defined for the System.String class. It’s defined inside a non-nested, non-generic static class:
namespace ExtensionMethods
{
public static class MyExtensions
{
public static int WordCount(this string str)
{
return str.Split(new char[] { ' ', '.', '?' },
StringSplitOptions.RemoveEmptyEntries).Length;
}
}
}


Leave a Reply