C# : how to return more then one result.
4/1/2014·2 min read
When make some function, you might need to return more than one result. There're few ways you can do that using C#.
- Return class. This works for different kind of type. For example, you can return int, string
- Return list of same type. This works if you return same type. For example, List.
- Return Tuple object.This also could return different kind of type.
1. Return class
definde a class. For example class Customer.
set value to the class, get the data.
2. Return list of same type data.
3. Use Tuple object to result different type of List values.
Lastly
I think Tuple is nice class, sometime, you want to return multi type of value by calling one method, but you don't want to create a new entity class to get that result. For this case, Tuple is good.
However, if you want to passing that result to use at many place, you should ceate a entity class. So, one in using in single method == Tuple. use as shared class == create entity class or using Generic List, etc.