How to explicitly discard an out argument?

后端 未结 8 1028
情歌与酒
情歌与酒 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 15:06

    Unfortunately you are required to pass something because the method is required to set it. So you cannot send null because the method, being required to set it, would blow up.

    One approach to hide the ugliness would be to wrap the method in another method that does the out parameter for you like so:

    String Other_MakeMyCall(String inputParams)
    {
        String messages;
    
        return MakeMyCall(inputParams, out messages);
    }
    

    Then you can call Other_MakeMyCall without having to fiddle with out parameters you don't need.

提交回复
热议问题