C# Programming
12-24-2009, 09:12 PM
I have a list of a custom type that contains 2 variables. One is name, the other is count. What is the general idea of what I need to do in order to condense this into a list with no duplicates where the counts of duplicate names are added together?
(eg. A list with 3 carls, 2 carls, 1 eric, 1 alex and 1 eric should condense to 5 carls, 2 ercis, 1 alex)
An example of the class the list would be populated with:
public class Person
{
private string _name;
public string PersonName
{
get {return _name;}
set { _name = value;}
}
private int _count;
public int PersonCount
{
get { return _count; }
set { _count = value; }
}
public Person(string name, int count)
{
_count = count;
_name = name;
}
}
(eg. A list with 3 carls, 2 carls, 1 eric, 1 alex and 1 eric should condense to 5 carls, 2 ercis, 1 alex)
An example of the class the list would be populated with:
public class Person
{
private string _name;
public string PersonName
{
get {return _name;}
set { _name = value;}
}
private int _count;
public int PersonCount
{
get { return _count; }
set { _count = value; }
}
public Person(string name, int count)
{
_count = count;
_name = name;
}
}