c# - 定义接口(interface)时 <> 是什么意思?

标签 c# .net class interface

我学习了如何编写自己的界面并看到了 MSDN 文章“Interfaces (C# Programming Guide)”。一切似乎都很好,除了: 是什么意思或做什么?

interface IEquatable<T>
{
    bool Equals(T obj);
}

最佳答案

表示它是一个generic界面。

你可以像这样创建一个界面:

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

您可以通过多种方式实现它:

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

像这样:

public class MyIntClass : IMyInterface<int>
{
    public int TheThing {get; set;}
}

关于c# - 定义接口(interface)时 <> 是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3962007/

相关文章:

c++ - 错误 C2027 : use of undefined type - how to declare class

c++ - 使用不同/未知类型的类模板初始化 vector

c# - 后台 Excel 线程未被杀死 C#

c# - 考虑到 sleep 时间,我如何测量代码某些部分的时间?

c# - 为多个设备创建相同的访问 token

c# - 方法 Enumerable.Where 中的两个候选人

c# - Ironpython:IEnumerator

c# - 奇怪的 StackOverflow 异常

.net - @font-face 在本地主机上工作正常,但在 AppHarbor 中不行

javascript - 用 TypeScript 编写的具有 protected /私有(private)字段的类可以从 JavaScript 中的类外部访问吗?