HashSet: overriding del metodo Add

FAQ di programmazione in .NET

HashSet: overriding del metodo Add

Messaggioda alesslud » ven gen 11, 2008 11:38 am

HashSet: overriding del metodo Add


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleProject
{
public class Program : HashSet<Person>
{
public static void Main(String[] arg)
{
Program g = new Program();
g.add(new Person("Hans"));
g.add(new Person("Lotte"));
g.add(new Person("Jane"));
g.add(new Person("Hans"));
g.add(new Person("Jane"));
Console.WriteLine("Total: " );
}

public Boolean add(Person o)
{
Console.WriteLine("Adding: " + o);
return base.Add(o);
}
}

public class Person
{
private String name;

public Person(String name)
{
this.name = name;
}

public String toString() {
return name;
}
}
}
alesslud
Site Admin
 
Messaggi: 779
Iscritto il: mer nov 08, 2006 8:09 am

Torna a .NET

Chi c’è in linea

Visitano il forum: Nessuno e 1 ospite

cron