Generic Interfaces and Structs

Implementing the Same Interface Multiple Times on a Single Class

public interface IContainer<T>
{
    ICollection<T> Items { get; set; }
}

public class Person : IContainer<string>, IContainer<int>, IContainer<bool>
{
    ICollection<string> IContainer<string>.Items { get; set; }
    ICollection<int> IContainer<int>.Items { get; set; }
    ICollection<bool> IContainer<bool>.Items { get; set; }
}

Defining a Constructor/Finalizer

public interface IPair<T>
{
    T First { get; set; }
    T Second { get; set; }
}
public struct Pair<T> : IPair<T>
{
    public T First { get; set; }
    public T Second { get; set; }

    public Pair(T first, T second)
    {
        First = first;
        Second = second;
    }
}

Specifying a Default Value for Value Types

public struct Pair<T>: IPair<T>
{
	/*
	// ERROR: Field 'Pair<T>.Second' must be fully assigned before control leaves the constructor
	public Pair(T first)
	{
		_First = first;
	}
	*/
}
public struct Pair<T> : IPair<T>
{
	public Pair(T first)
	{
		First = first;
		Second = default(T);
	}
}

Constraints

Interface Constraints

public class BinaryTree<T> 
	where T : IComparable<T> { /* ... */ }