I have a very simple test method that returns a List that has a number of duplicates, but when it did not I thought I'd try HashSet as that should remove duplicates, but it appears I need to override the Equals and GetHashCode but I am really struggling to understand what I need to do. I would appreciate some pointers please.
HashSet<object> test = XmlManager.PeriodHashSet(Server.MapPath("../Xml/XmlFile.xml"));
foreach (Object period in test2)
{
PeriodData pd = period as PeriodData;
Response.Write(pd.PeriodName + "<br>");
}
I also tried it with the following
List<object> test = XmlManager.PeriodList(Server.MapPath("../Xml/XmlFile.xml"));
List<object> test2 = test.Distinct().ToList();
foreach (Object period in test2)
{
PeriodData pd = period as PeriodData;
Response.Write(pd.PeriodName + "<br>");
}
The PeriodData objuect is delcarewd as follows:
public class PeriodData
{
private int m_StartYear = -9999999;
private int m_EndYear = -9999999;
private string m_PeriodName = String.Empty;
public int StartYear
{
get { return m_StartYear; }
set { m_StartYear = value; }
}
public int EndYear
{
get { return m_EndYear; }
set { m_EndYear = value; }
}
public string PeriodName
{
get { return m_PeriodName; }
set { m_PeriodName = value; }
}
}
It is the returned PeriodName I want to remove the duplicate for.