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);
}
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;}
}
它是一个参数类型意味着你可以重用任何类型的IEquatable ...在“运行时”(但不完全),代替T,你可以使用String,Animal,Dog ecc ......
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.