【问题标题】:Using a out parameter in Func Delegate在 Func Delegate 中使用 out 参数
【发布时间】:2012-12-28 10:55:25
【问题描述】:

我有一个方法签名

bool TryGetItem(string itemKey,out Item item)

我怎样才能把这个签名封装在

delegate V Func<T,U,V>(T input, out U output)

如在帖子中:Func<T> with out parameter?

【问题讨论】:

    标签: c#-4.0 delegates func


    【解决方案1】:

    你只是书面回答。

    如果您在 .net 4.0 或更高版本中,您可以为参数指定方差。

    public delegate TV MyFunc<in T, TU, out TV>(T input, out TU output);
    

    然后使用:

    bool TryGetItem(string itemKey,out Item item);
    
    MyFunc<string, Item, bool> func = TryGetItem;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-30
      • 2021-04-23
      • 1970-01-01
      相关资源
      最近更新 更多