Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created June 24, 2021 20:12
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 parzibyte/0a4713bdb76d11d8b7888a0d5b02533e to your computer and use it in GitHub Desktop.
Save parzibyte/0a4713bdb76d11d8b7888a0d5b02533e to your computer and use it in GitHub Desktop.
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