-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
54 lines (45 loc) · 1.19 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System;
using System.Collections.Generic;
namespace Icomparable
{
class persona:IComparable
{
int id;
string nombre;
public persona(int id,string nombre)
{
this.id=id;
this.nombre=nombre;
}
public override string ToString()
{
return String.Format("{0},{1}",id,nombre);
}
public Int32 CompareTo(object o)
{
return this.id.CompareTo(((persona)o).id);
}
}
class Program
{
static void Main()
{
Console.WriteLine("Lista de personas ");
List<persona> pers=new List<persona>();
pers.Add(new persona(2,"Pam"));
pers.Add(new persona(1,"Jim"));
pers.Add(new persona(3,"Mike"));
foreach(persona p in pers)
{
Console.WriteLine(p);
}
Console.WriteLine("------------------------------");
Console.WriteLine("Lista de personas organizada por id");
pers.Sort();
foreach(persona p in pers)
{
Console.WriteLine(p);
}
}
}
}