efficiently creating List<ClassB> from List<ClassA>?

Viewed 98

I have objects from ClassA and want to use them to create objects of ClassB. I know how to do that if I'm just dealing with one object at a time:

ClassA object1 = new ClassA();
ClassB object2 = new ClassB(object1);

class ClassA
{
    public DateTime Timestamp;
    public double X;
    public double Y;
    public double Z;

    public ClassA()
    {
       // other stuff
    }
}

class ClassB
{
    public DateTime Timestamp;
    public double X;

    public ClassB(ClassA A)
    {
        Timestamp = A.Timestamp;
        X = A.X;
    }
}

However, I'm looking for the best way to do it with lists of objects. I want to take the list of type ClassA, and create a list of type ClassB:

List<ClassA> list_of_classA = new List<ClassA>();
List<ClassB> list_of_classB = ????
4 Answers
Related