An extension method in C# is a static method that allows you to add new functionality to an existing class without modifying its source code or inheriting from it.
Extension methods enable you to "extend" the behavior of a class by providing new methods that can be called on instances of that class as if they were part of the class's original API.
To define an extension method, you need to create a static class that contains the extension method as a static method. The first parameter of the extension method must be marked with the this keyword followed by the name of the type you want to extend. This tells the C# compiler that the extension method should be treated as a member of the extended type. You can then call the extension method on an instance of the extended type as if it were a regular member method.
Here's an example of an extension method that adds a new method called Increment to the int type:
namespaceConsoleAppTest{internalclassProgram{privatestaticvoidMain(string[]args){try{varcustomers=newList<Customer>();customers.Add(newCustomer(25));customers.Add(newCustomer(5));customers.Add(newCustomer(15));customers=customers.AboveAge(10);foreach(varcustomerincustomers){Console.WriteLine(customer.ToString());}}catch(Exception){throw;}finally{Console.WriteLine("Press Any Key to Exit");Console.ReadLine();}}}internalclassCustomer{publicintAge{get;set;}publicCustomer(intage){Age=age;}publicoverridestringToString(){returnAge.ToString();}}internalstaticclassCustomerHelper{publicstaticList<Customer>AboveAge(thisList<Customer>customers,intage){returncustomers.FindAll(c=>c.Age>age);}}}