Content deleted Content added
→Extension methods: syntax highlighting |
rewrite |
||
Line 43:
;With extension methods: <source lang="csharp">x.Operation1(arg1).Operation2(arg2)</source>
==Extension methods and Instance methods==
In C# 3.0, both an instance method as well as an extension method with the same signature can exist for a class. In such a scenario, the instance method is preferred over the extension method. Neither the compiler nor the [[Microsoft Visual Studio]] IDE warns about the naming conflict. Consider this C# code:
<source lang="csharp">
class AlphabetMaker
static class ExtensionMethods▼
{
{ //it will shadow the implementation
Console.WriteLine("abc"); //in the ExtensionMethods class.
}
}
▲static class ExtensionMethods
{
static public
{ //if there is no instance
Console.WriteLine("ABC"); //method with the same signature.
}
}
</source>
Result with the instance method not implemented:
ABC
Result with the instance method implemented:
abc
==See also==
|