Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created Jun 24, 2021
Embed
What would you like to do?
using System;
using System.Collections.Generic;
namespace App
{
class Persona
{
public string nombre;
public Persona(string nombre)
{
this.nombre = nombre;
}
public override string ToString()
{
return "Persona con nombre " + this.nombre;
}
}
class Programa
{
static void recorrerArregloGenerico<T>(IList<T> arreglo)
{
foreach (var elemento in arreglo)
{
Console.WriteLine(elemento);
}
}
/*
https://parzibyte.me/blog
*/
static void Main(string[] args)
{
int[] numeros = { 999, 28, 11, 96, 1, 2, 45, 0, 1 };
string[] cadenas = { "Hola", "Mundo" };
Persona[] personas = { new Persona("Luis"), new Persona("María") };
recorrerArregloGenerico(numeros);
recorrerArregloGenerico(cadenas);
recorrerArregloGenerico(personas);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment