How can I clone a DateTime object in C#?

前端 未结 3 1282
南旧
南旧 2021-02-11 12:05

How can I clone a DateTime object in C#?

3条回答
  •  孤独总比滥情好
    2021-02-11 12:15

    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.

提交回复
热议问题