Extension Methods
- This is a feature of C# 3.0.
Extension methods are a form of syntactic sugar providing the illusion of adding new methods to the existing class outside its definition. In practice, an extension method is a static method that is callable as if it were an instance method; the receiver of the call is bound to the first parameter of the method, decorated with keyword this:
public static class StringExtensions { public static string Left(this string s, int n) { return s.Substring(0, n); } } string s = "foo"; s.Left(3); // same as StringExtensions.Left(s, 3);See also
- Decorator pattern
Read more about this topic: C Sharp Syntax
Famous quotes containing the words extension and/or methods:
“We know then the existence and nature of the finite, because we also are finite and have extension. We know the existence of the infinite and are ignorant of its nature, because it has extension like us, but not limits like us. But we know neither the existence nor the nature of God, because he has neither extension nor limits.”
—Blaise Pascal (16231662)
“In inner-party politics, these methods lead, as we shall yet see, to this: the party organization substitutes itself for the party, the central committee substitutes itself for the organization, and, finally, a dictator substitutes himself for the central committee.”
—Leon Trotsky (18791940)