Leo
✅ Deep copy struct
public struct MyStruct
{
public int[] Array;
public MyClass Class;
public MyStruct DeepCopy()
{
var newStruct = new MyStruct();
newStruct.Array = new int[this.Array.Length];
Array.Copy(this.Array, newStruct.Array, this.Array.Length); // Copy elements
// Assuming MyClass has a custom method for deep copying
newStruct.Class = this.Class.DeepCopy(); // Implement DeepCopy in MyClass
return newStruct;
}
}
public class MyClass
{
public int Property; // Example property
public MyClass DeepCopy()
{
return new MyClass { Property = this.Property }; // Adjust for your properties
}
}
90 replies
✅ Deep copy struct
public struct MyStruct
{
public int[] Array;
public MyClass Class;
public MyStruct DeepCopy()
{
var newStruct = this; // Create a copy of the struct
newStruct.Array = (int[])this.Array.Clone(); // Deep copy of the array
newStruct.Class = (MyClass)this.Class.MemberwiseClone(); // Deep copy of the class
return newStruct;
}
}
90 replies