ASP.net best way to Return Multiple Values from a Function
From .NET Framework 4 Tuple class has been introduce to create combination of heterogeneous objects .Its can used to group different types of items (objects ) and indicate this group as single object.
Tuple is a class and once you create the Tuple, you cannot change the types of the items or the values assigned in the creation. This makes the Tuple more like a struct.
However this enable much safe way to return distinct number of multiple elements to be returned for a function .
Example function(return Boolean and string )
public class Class1
{
public static Tuple<Boolean, String> ExampleFunction(string parameterVal)
{
Boolean retunValue1= false;
string retunValue2 = "";
.......
return Tuple.Create(retunValue1, retunValue2 );
}
}
Calling Function and Retrieve return Values
var retTuple = Class1.ExampleFunction(parameterVal);
Boolean retriveValue1 = retTuple.Item1;
String retriveValue2 = retTuple.Item2;
Comments
Post a Comment