How can I clone a DateTime object in C#?

前端 未结 3 1872
伪装坚强ぢ
伪装坚强ぢ 2021-02-11 11:55

How can I clone a DateTime object in C#?

3条回答
  •  星月不相逢
    2021-02-11 12:36

    var original = new DateTime(2010, 11, 24);
    var clone = original;
    

    DateTime is a value type, so when you assign it you also clone it. That said, there's no point in cloning it because it's immutable; typically you'd only clone something if you had the intention of changing one of the copies.

提交回复
热议问题