I need to return multiple items from a function. How can I do that?
public List<string> GetInfo()
{
var result = new List<string>();
return result;
}
How can I return something like this? Basically List of string and maybe also a list of generic type.
public List<string> GetInfo()
{
var result = new List<string>();
return result and someType;
}
public class someType
{
public List<SomeOthertype> someOthertype { get; set; }
}
>Solution :
If I understand you right, you can try using named tuples:
public (List<string> result, List<SomeOthertype> other) GetInfo()
{
var result = new List<string>();
someType instance = new someType();
//TODO: put relevant code here
// we return both result and someOthertype in one tuple
return (result, instance.someOthertype);
}
Usage:
var info = GetInfo();
var result = info.result;
var other = info.other;