Here I have a list of Column
objects. Each Column
object has several properties that may be unique or not. Here is an example code I have written so far.How can I remove the duplicates from columns
list so that in the final list I only have c1 and c2?
Program.cs
var pc1 = new PartialColumn { Section = "C50" };
var pc2 = new PartialColumn { Section = "C40" };
var c1 = new Column
{
X = 0,
Y = 0,
StartElevation = 0,
EndElevation = 310,
FoundationHeight = 60,
ListOfPartialColumns = new List<PartialColumn> {pc1}
};
var c2 = new Column
{
X = 600,
Y = 0,
StartElevation = 0,
EndElevation = 630,
FoundationHeight = 60,
ListOfPartialColumns = new List<PartialColumn> { pc1, pc2 }
};
var c3 = new Column
{
X = 600,
Y = 0,
StartElevation = 0,
EndElevation = 630,
FoundationHeight = 60,
ListOfPartialColumns = new List<PartialColumn> { pc1, pc2 }
};
var columns = new List<Column> {c1, c2, c3};
PartialColumn.cs
public class PartialColumn
{
public string Section { get; set; }
}
Column.cs
public class Column
{
public double StartElevation { get; set; }
public double EndElevation { get; set; }
public double X { get; set; }
public double Y { get; set; }
public List<PartialColumn> ListOfPartialColumns { get; set; }
public double FoundationHeight { get; set; }
}
Update:
I want to remove the duplicates from the columns list. As you can see, c2 and c3 have the same properties. I want to remove c3.