Is there way to add new method to List object over the object from which it’s made of .In other word can class be written in such way ,when List is made from it that it adds new method to that List. Here’s an exemple:
class Employee
{
public int age;
public Employee(int age)
{
this.age = age;
}
//some more code here...
}
And then:
List<Employee> sector01 = new List<Employee>(){new Employee(22), new Employee(35)};
sector01.OutputAll(); //Adds method like this
You could define it as an extension method:
and then simply bring the namespace where this static class is defined into scope:
and now you will be able to do this: