Return multiple values to a method caller

前端 未结 26 2718
故里飘歌
故里飘歌 2020-11-21 21:57

I read the C++ version of this question but didn\'t really understand it.

Can someone please explain clearly if it can be done and how?

26条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-21 22:54

    You either return a class instance or use out parameters. Here's an example of out parameters:

    void mymethod(out int param1, out int param2)
    {
        param1 = 10;
        param2 = 20;
    }
    

    Call it like this:

    int i, j;
    mymethod(out i, out j);
    // i will be 20 and j will be 10
    

提交回复
热议问题