Created
March 27, 2016 18:55
-
-
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#.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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