I have two lists. BeamElevations<Elevation>
and FloorElevations<Elevation>
. How can I merge these into Elevations<Elevation>
list and order them based on their Elevation using Linq?
I have two lists. BeamElevations<Elevation>
and FloorElevations<Elevation>
. How can I merge these into Elevations<Elevation>
list and order them based on their Elevation using Linq?
var result = list1.Concat(list2).OrderBy(x => x.Elevation).ToList();
If you want to remove duplicates and get an unique set of elements you can also use Union
method:
var result = list1.Union(list2).OrderBy(x => x.Elevation).ToList();
In order to make it work properly you need to overide Equals
and GetHashCode
methods in your class.