小编DJ *_*tiX的帖子

使用接口将泛型委托转换为另一种类型

(使用.NET 4.0)好的,我有

private Dictionary<int, Action<IMyInterface, IMyInterface>> handler {get; set;}

public void Foo<T, U>(Action<T, U> myAction)
    where T : IMyInterface
    where U : IMyInterface
    {
        // | This line Fails
        // V
        Action<IMyInterface, IMyInterface> anotherAction = myAction;
        handler.Add(someInt, anotherAction);
    }
Run Code Online (Sandbox Code Playgroud)

我正在尝试将委托存储在一个泛型集合中,所以我可以稍后将其拉回来调用它.我该如何正确施展它?

c# generics xna delegates casting

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

标签 统计

c# ×1

casting ×1

delegates ×1

generics ×1

xna ×1