how to return multiple values from a method in c# code example
Example 1: how to find the multiples of 3 c#
static void PrintNumbers()
{
for (int i = 1; i <= 100; i++)
{
if (i % 3 == 0 && i % 5 == 0)
{
Console.WriteLine(i + " FizzBuzz");
}
else if ( i % 3 == 0)
{
Console.WriteLine(i + " Fizz");
}
else if (i % 5 == 0)
{
Console.WriteLine(i + " Buzz");
}
else
{
Console.WriteLine(i);
}
}
}
Example 2: c# return two variables of different types
(string, string, int) LookupName(long id)
{
...
return (first, middle, myNum);
}
Example 3: c# method returns multiple values
public Tuple<int, int> GetMultipleValue()
{
return Tuple.Create(1,2);
}