60 678
Assignments Done
97,7%
Successfully Done
In April 2018

Answer to Question #69985 in C# for Omar

Question #69985
Which two way I can use to make a method return a int and string.
Expert's answer
/*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!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions