-
-
Save parzibyte/5af226a7c07d85c5dc5d8135437d0b9a to your computer and use it in GitHub Desktop.
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.Collections.Generic; | |
namespace App | |
{ | |
class Persona | |
{ | |
public string nombre; | |
public int edad; | |
public Persona(string nombre, int edad) | |
{ | |
this.nombre = nombre; | |
this.edad = edad; | |
} | |
public override string ToString() | |
{ | |
return "Persona con nombre " + this.nombre + " y edad " + this.edad; | |
} | |
public void saludar() | |
{ | |
Console.WriteLine("Me llamo " + this.nombre); | |
} | |
} | |
class Programa | |
{ | |
static int longitudDeArreglo<T>(IList<T> arreglo) | |
{ | |
int longitud = 0; | |
foreach (var elemento in arreglo) longitud++; | |
return longitud; | |
} | |
static int longitudDeArregloEntero(int[] arreglo) | |
{ | |
int longitud = 0; | |
foreach (var elemento in arreglo) longitud++; | |
return longitud; | |
} | |
/* | |
https://parzibyte.me/blog | |
*/ | |
static void Main(string[] args) | |
{ | |
// int[] arreglo = { 999, 28, 11, 96, 1, 2, 45, 0, 1 }; | |
// string[] arreglo = { "Hola", "Mundo" }; | |
Persona[] arreglo = { new Persona("Luis", 24), new Persona("María", 24) }; | |
int longitud = longitudDeArreglo(arreglo); | |
int longitudConLength = arreglo.Length; | |
Console.WriteLine("La longitud según método es {0}, y según .Length es {0}", longitud, longitudConLength); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment