This is just a random tip about Generic Collections. Sometimes it’s common for me to create a class which can be used in a collection. In most cases I use a generic collection of this type as a data source and such things and instead of typing everywhere List<T> and replacing T with the type I just created; I create a new class which extends from this a generic collection of this type. Just a sample: public class Subscriber {
public string FirstName { get; set; }
public string LastName { get; set; }
public string EmailAddress { get; set; }
public string IssueId { get; set; }
public string FullName {
get { return string.Format("{0} {1}", this.FirstName, this.LastName); }
}
}Now, every time I need to instantiate a collection of Subscriber I will have to type something like this:
List<Subscriber> list = new List<Subscriber>();
The idea here is simple. We can write a code as simple as this:
public class Subscribers : List<Subscriber> { }And now I can use the following code to create an instance of our collection of Subscriber:
Subscribers list = new Subscribers();
In the end of the day, it’s just the same thing, but the advantage this is that with inheritance and polymorphism you can add other methods to your collection to handle the needs of your custom type.