Which two way I can use to make a method return a int and string.
/*first way is to use out parameters*/
public void GetStringAndInt(out int intVar, out string stringVar)
{
intVar = 123;
stringVar = "abc";
}
/*second way is a function that returns your own class*/
public IntAndString GetStringAndInt()
{
var intAndString = new IntAndString();
intAndString.intVal = 123;
intAndString.stringVal = "abc";
return intAndString;
}
public class IntAndString
{
public int intVal { get; set; }
public string stringVal { get; set; }
}
/*third way - use a Tuple class (availibale from 4.0 framework)*/
public Tuple<int, string> GetStringAndInt()
{
return Tuple.Create(123, "abc");
}
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Learn more about our help with Assignments:
C#