Return multiple values to a method caller

前端 未结 26 2306
故里飘歌
故里飘歌 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:33

    Ways to do it:

    1) KeyValuePair (Best Performance - 0.32 ns):

        KeyValuePair Location(int p_1, int p_2, int p_3, int p_4)
        {                 
             return new KeyValuePair(p_2 - p_1, p_4-p_3);
        }
    

    2) Tuple - 5.40 ns:

        Tuple Location(int p_1, int p_2, int p_3, int p_4)
        {
              return new Tuple(p_2 - p_1, p_4-p_3);
        }
    

    3) out (1.64 ns) or ref 4) Create your own custom class/struct

    ns -> nanoseconds

    Reference: multiple-return-values.

提交回复
热议问题