Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created March 27, 2016 18:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fhernd/e062e0af42a7745df414 to your computer and use it in GitHub Desktop.
Save Fhernd/e062e0af42a7745df414 to your computer and use it in GitHub Desktop.
Demostración retorno de múltiples valores desde una función en C#.
using System;
using System.Linq;
namespace Articulo.Pregunta.P2020
{
public class MultiplesValoresRetorno
{
public static void Main()
{
// Declaración arreglo con valores enteros:
int[] arregloEnteros = new int[] {61, 13, 5, 23, 29};
// Cómputo de máximo y mínimo:
MaximoMinimo maxMinResultado = ObtenerMaximoMinimo(arregloEnteros);
// Visualización de resultados:
Console.WriteLine ("\nMáximo: {0}; mínimo: {1}\n", maxMinResultado.Maximo, maxMinResultado.Minimo);
}
// Calcula el máximo y mínimo de un arreglo de enteros:
public static MaximoMinimo ObtenerMaximoMinimo(int[] valores)
{
MaximoMinimo maxMin = new MaximoMinimo();
maxMin.Maximo = valores.Max();
maxMin.Minimo = valores.Min();
return maxMin;
}
}
// Estructura para representar el máximo y el máximo de números enteros:
public struct MaximoMinimo
{
private int maximo;
private int minimo;
public int Maximo
{
get
{
return maximo;
}
set
{
maximo = value;
}
}
public int Minimo
{
get
{
return minimo;
}
set
{
minimo = value;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment