C# memcpy equivalent

后端 未结 8 657
野的像风
野的像风 2020-12-11 05:11

I have 2 objects from the same type and i would like to shallow copy one state to the other. In C++ i have memcpy which is great. How can i do it in C#? The MemberwiseClone(

8条回答
  •  无人及你
    2020-12-11 05:28

    I guess you could just do something like:

    YourObjectType A = new YourObjectType();
    YourObjectType B = a.MemberwiseClone();
    

    This will create a new object inside the MemberwiseClone method an make the B object reference it. I guess it serves your purposes.

提交回复
热议问题