Skip to content

Instantly share code, notes, and snippets.

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