gpt4 book ai didi

c# - 我应该使用接口(interface)来强制泛型吗?

转载 作者:太空宇宙 更新时间:2023-11-03 19:31:49 26 4
gpt4 key购买 nike

如果我有以下通用接口(interface):

    public interface IValidator<T>
{
Boolean IsValid(T entity_);
}

我可以通过以下方式使用它吗?这是否违反面向对象编程指南?

    public PathValidator : IValidator<String>
{
}

最佳答案

Is that use of Interfaces against any sort of best practice?

不,这很好而且很常见(假设您的接口(interface)不为空并且具有类似 bool IsValid(T entity) 的方法签名)。

是什么让您认为它应该是?如果您让我们知道,我们可以详细说明。

关于c# - 我应该使用接口(interface)来强制泛型吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4430258/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com