Scan with Phone

Scan to instantly open and share this page on your mobile device.

Link copied to clipboard!

Prototype

Clone existing exemplar instead of building from scratch.

C#

public interface IPrototype<T>
{
    T Clone();
}
public record Node(string Name, List<int> Data) : IPrototype<Node>
{
    public Node Clone()
    {
        return this with { Data = new List<int>(Data) }; // deep copy list
    }
}
var original = new Node("A", new(){1,2});
var copy = original.Clone();
copy.Data.Add(3); // original unaffected
next