C# Automatic deep copy of struct

前端 未结 6 1979
没有蜡笔的小新
没有蜡笔的小新 2021-01-17 10:53

I have a struct, MyStruct, that has a private member private bool[] boolArray; and a method ChangeBoolValue(int index, bool Value). <

6条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-17 11:36

    Struct is copied when passed right? So:

    public static class StructExts
    {
        public static T Clone ( this T val ) where T : struct => val;
    }
    

    Usage:

    var clone = new AnyStruct ().Clone ();
    

提交回复
热议问题