小编Syt*_*one的帖子

通用字典,其值为具有通用引用的接口

我想要一个字典,其中值是通用对象,并且对于字典中的每个值都不相同.怎么能这样做,我觉得我错过了一些简单的事情.

例如


    public interface IMyMainInterface
    {
        Dictionary<string, IMyInterface<T>> Parameters { get; }
    }

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

        void SomeFunction();
    }

Result:
dic.Add("key1", new MyVal<string>());
dic.Add("key2", new MyVal<int>());

Run Code Online (Sandbox Code Playgroud)

.net c# generics

3
推荐指数
1
解决办法
7466
查看次数

标签 统计

.net ×1

c# ×1

generics ×1