aAaAeEBCfBeXWBC| 576645}4WCWZ 56655VCBZC-

Extension.` An extension method has simplified calling syntax. It represents a static method as an instance method. Extension methods can lead to simpler syntax.`This keyword.` An extension method uses the this-keyword in its parameter list. It must be located in a static class. We often use special "Extensions" classes.`An example.` Here is a custom extension method. Usually you will want to store your extension method class in a separate source file (like ExtensionMethods.cs) in the project. `This file should store a static class with public static extension methods.`Public `public`Then: `In the rest of your source code, you can invoke these extension methods in the same way as instance methods.`Notes, above program.` You can see an extension method declaration. An extension method must be static and can be public so you can use it anywhere in your source code. `The extension method is called like an instance method, but is actually a static method. The instance pointer "this" is a parameter.`You must specify the this-keyword before the appropriate parameter you want the method to be called upon.`Notes, continued.` The only difference in the declaration between a regular static method and an extension method is the "this" keyword in the parameter list. `Important: `If you want the method to receive other parameters, you can include those at the end.`Second parameter.` Here is an extension method that acts on ints. It receives a parameter—the multiplier for the operand. It returns another int so can be used in function call chains. `Return `return`LINQ.` There are many extension methods available. These extension methods were written by Microsoft developers and are available in all C# programs targeting recent .NET Framework versions. `On most of the extension methods, you need to add the "using System.Linq" directive to the top of the code.`LINQ `linq`A discussion.` Extension methods can have many arguments. We can use variable "params" arguments with extension methods. Extension methods are static methods—so there is no performance loss. `Params `params`So: `Extension methods affect the high-level representation of the code, not the low-level implementation.`A summary.` You can add extension methods to any type, even a value type. The original representation of the type does not change. Extension methods affect syntax, not execution.

OIRNHRRIDIQIbIBI?IJExtensionMIgsR{ROIBI?IP HUppercaseFirstLetterH(HthisH IP Ih)RO{HROOI{UpperIfthe first letterIpthe IP.ROOHImIh.LI^ > 0)ROO{ROOOchar[] IUIyIh.ToCharIS();ROOOIU[0]Iychar.ToUpper(IU[0]);ROOOIK IqIP(IU);ROO}ROOIK Ih;RO}R}RRIJIAR{ROI%O{HROOI{Use the IP extension mIg on this Ih.ROOHIP IhIyHNdot net perlsNH;ROOIhIyIh.HUppercaseFirstLetterH();ROOI'Ih);RO}R}RRHRRHDHot net perlsHRRIDIQIbI?IJExtensionsR{ROIBI?IiHMultiplyByH(this IiIh, Iimulitiplier)RO{HROOI{Uses a second parameter after the instance parameter.ROOHIK Ih * mulitiplier;RO}R}RRIJIAR{ROI%O{HROOI{Ten times 2 is 20.ROOI{Twenty times 2 is 40.ROOHIiIMIy10.HMultiplyByH(2).HMultiplyByH(2);ROOI'IM);RO}R}RRHRR40H

"jnextension method on stringextension method, 2 parameters