Can I have an Action<> or Func<> with an out param?

后端 未结 2 1896
不知归路
不知归路 2021-02-03 19:37

I have a method with an out parameter, and I\'d like to point an Action or Func (or other kind of delegate) at it.

This works fine

2条回答
  •  生来不讨喜
    2021-02-03 19:53

    No, not with the builtin delegates. out and ref are special qualifiers and the delegate has to be setup with them explicitly since they are completely different calling styles.

    However, if you defined your own delegate, you can do this:

    delegate void OutAction(out T1 a, out T2 b);
    

提交回复
热议问题