Good I created the following List, and added several elements as I show next:
List<Persona> personas = new List<Persona>();
personas.Add(new Persona("12345678C", "Juan Francisco Cabello"));
personas.Add(new Persona("26810168B", "Jesus Romero Gonzalez"));
personas.Add(new Persona("32167678V", "Guillermo Barcia"));
for (int i = 0; i < personas.Count; i++)
{
Console.WriteLine("INTRODUCIDO: " + personas[i].toString());
sw.WriteLine(personas[i].toString());
sw.WriteLine();
}
The problem is that the console, only shows me the last element ("Guillermo Barcia").
There I leave the Person class
class Persona : IComparable<Persona>
{
#region Atributos
private static string dni;
private static string nombre;
#endregion
#region Propiedades
public string Dni { get => dni; set => dni = value; }
public string Nombre { get => nombre; set => nombre = value; }
#endregion
#region Constructores
public Persona(string dn, string nom)
{
dni = dn;
nombre = nom;
}
public Persona() { }
#endregion
#region CompareTo
public int CompareTo(Persona other)
{
throw new NotImplementedException();
}
#endregion
#region ToString
public string ToString()
{
return "Nombre: " + nombre + "\n" +
"DNI: " + dni;
}
#endregion
}