Using Action as an argument in C# (mimicking a function pointer)

后端 未结 4 816
眼角桃花
眼角桃花 2021-02-06 08:05

I need to write a delegate function that can \'wrap\' some while/try/catch code around a basic UDP call to verify the link. I made it work for Func for a function that has no ar

4条回答
  •  Happy的楠姐
    2021-02-06 08:33

    Do you mean:

        protected void udpCommand(Action command, T value) {...}
    

    With calling:

    udpCommand(someUdpCommand, arg);
    

    Note that this may work better on C# 3.0, which has stronger generic type inference than C# 2.0.

提交回复
热议问题