Alex Rivera | Logout

Copy a class to another?

Asked 2010-01-14T22:11:31.137
10

I have

class A
{
    public int a;
    public string b;
}

How can i copy A to another A? In C++ i know i could do *a1 = *a2;. Is there something similar in C#? I know i could write a generic solution using reflection but i hope something exist already.

I'm considering changing A to a nullable struct.

Step 2 i'll need to do

class B : A {}
class C : A {}

and copy the base data from B to C.

Edit
Report

1 Answer

0

You can Clone, you can define a copy constructor. Why change class to struct just because in C++ you can do something in 10 characters. C# is different. Structs have advantages and disadvantages.

answered 2010-01-14T22:14:05.947

Your Answer