Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does <> mean when defining an interface?

I learning about writing my own interfaces and came across the MSDN article "Interfaces (C# Programming Guide)". Everything seems fine, except: what does <T> mean or do?

interface IEquatable<T>
{
    bool Equals(T obj);
}
like image 282
m.edmondson Avatar asked Nov 29 '22 17:11

m.edmondson


1 Answers

It means that it is a generic interface.

You could create an interface like this:

public interface IMyInterface<T>
{
    T TheThing {get; set;}
}

and you could implement it in various ways:

public class MyStringClass : IMyInterface<string>
{
    public string TheThing {get; set;}
}

and like this:

public class MyIntClass : IMyInterface<int>
{
    public int TheThing {get; set;}
}
like image 150
Klaus Byskov Pedersen Avatar answered Dec 02 '22 07:12

Klaus Byskov Pedersen