Thursday, June 3, 2010

Generic Interface using C#

interface IUnique<T>
{
T Id { get; }
}

//implement interface with specific types
class MyObject : IUnique<int>
{
private int _id;
//implementation of interface’s method
public int Id
{
get { return _id; }
}
}

class MyOtherObject : IUnique<string>
{
private string _id;
public string Id
{
get { return _id; }
}
}

No comments:

Post a Comment