Q:

Get Distinct values out of List

I have a List that contains instances of Beam class. Each of these Beam objects has an Elevation property.
List<Beam> Beams = new List<Beam> {Beam1, Beam2, ...};

public class Beam
{
    public double Elevation;
}

Now I want to create a List<double> that contains distinct Elevations.
For example how to write a method that accepts the Beams list as below
var Beam1 = new Beam { Elevation = 320);
var Beam2 = new Beam { Elevation = 320);
var Beam3 = new Beam { Elevation = 640);
var Beam4 = new Beam { Elevation = 0);

List<Beam> Beams = new List<Beam> {Beam1, Beam2, Beam3, Beam4};

And gives this removing the duplicate elevations:
listOfElevations = {0, 320,640}

A:

1) Make Beam implement IComparable:
public class Beam : IComparable
{
    public double Elevation; //consider changing this to property, btw.

    public int CompareTo(object obj) {
         if (obj == null) return 1;

         Beam otherBeam = obj as Beam;
         return this.Elevation.CompareTo(otherBeam.Elevation);
    }
}

2) use Distinct():
var listOfElevations = Beams.Distinct().Select(x=> x.Elevation).ToList();

