Defining Extension Methods
Create a new Console Application named ExtensionMethods. Now, assume you are authoring a
utility class named MyExtensions that defines two extension methods. The first method allows
any object in the .NET base class libraries to have a brand-new method named
DisplayDefiningAssembly() that makes use of types in the System.Reflection namespace to
display the assembly of the specified type.
The second extension method, named ReverseDigits(), allows any System.Int32 to obtain a
new version of itself where the value is reversed digit by digit. For example, if an integer with the
value 1234 called ReverseDigits(), the integer returned is set to the value 4321. Consider the follow-
ing class implementation:
static class MyExtensions
{
Do'stlaringiz bilan baham: |