What is the method MemberwiseClone() doing?
What is the method MemberwiseClone() doing?
The MemberwiseClone() method in C# creates a shallow copy of the current object. Here's what it does:
In other words, MemberwiseClone() creates a new object with the same field values as the original object, but it does not create new copies of the referenced objects. This means that if the original object has reference type fields, both the original object and the cloned object will reference the same objects.
Here's an example:
class Person
{
Đăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.