Method should return multiple values

后端 未结 7 1073
执笔经年
执笔经年 2020-12-19 09:10

Hii

I have method in C#, I have to return multiple values from that method with out using collections like arrays. Is there any reliable way ?

相关标签:
7条回答
  • 2020-12-19 09:42

    Well, you could use:

    • a custom class/struct/type, containing all your values
    • out parameters

    I.e.:

    class MyValues
    {
        public string Val1 { get; set; }
        public int Val2 {get; set; }
    }
    
    public MyValues ReturnMyValues();
    

    or

    public void ReturnMyValues(out string Val1, out int Val2);
    
    0 讨论(0)
提交回复
热议问题