gpt4 book ai didi

C# 泛型和集合

转载 作者:行者123 更新时间:2023-11-30 21:24:25 24 4
gpt4 key购买 nike

我有两个接口(interface)定义如下:

public interface IFoo
{
...
}

Public interface IFooWrapper<T> where T : IFoo
{
T Foo {get;}
}

我希望能够声明一个 IFooWrappers 集合,但我不想指定 IFoo 的实现。

理想情况下我想做这样的事情:

IList<IFooWrapper<*>> myList;

我想不出解决这个问题的方法。

最佳答案

public interface IFoo
{
...
}

public interface IFooWrapper : IFoo
{
...
}
public interface IFooWrapper<T> : IFooWrapper
where T : IFoo
{
...
}
IList<IFooWrapper> myList;

这是一种做你想做的事情的方法

关于C# 泛型和集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1226576/

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