Jibu P C_Adoor Jibu P C_Adoor - 2 months ago 14
C# Question

Method should return multiple values

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 ?

Answer

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);