Func / Action delegates with reference arguments/parameters or anonymous functions

后端 未结 2 782
甜味超标
甜味超标 2021-01-12 09:10

I just wondered, how the exact syntax is for ref and out parameters for delegates and inline lambda functions.

here is an example

i

2条回答
  •  生来不讨喜
    2021-01-12 09:50

    You can't use Action, Func, or the built-in delegates, but need to define your own in this case:

    delegate void ActionByRef(ref T value);
    

    Then, given this, you can have:

    int value = 3;
    ActionByRef f2 = DoSomething;
    f2(ref value);
    

提交回复
热议问题