How to explicitly discard an out argument?

后端 未结 8 1037
情歌与酒
情歌与酒 2020-12-09 14:30

I\'m making a call:

myResult = MakeMyCall(inputParams, out messages);

but I don\'t actually care about the messages. If it was an input pa

8条回答
  •  一向
    一向 (楼主)
    2020-12-09 14:51

    If the original function is declared like this:

    class C
    {
        public Result MakeMyCall(Object arg, out List messages);
    }
    

    You can declare an extension method like this:

    static class CExtension
    {
        public static Result MakeMyCall(this C obj, Object arg)
        {
            List unused;
            return obj.MakeMyCall(arg, out unused);
        }
    }
    

    The extension method will behave like an overload that makes the out parameter optional.

提交回复
热议问题