If DateTime is immutable, why does the following work?

前端 未结 6 1486
轻奢々
轻奢々 2021-01-03 20:34

I thought I understood what Immutable meant, however I don\'t understand why the following compiles and works:

DateTime dt = DateTime.Now;

Console.WriteLine         


        
6条回答
  •  [愿得一人]
    2021-01-03 21:37

    You're simply telling the variable dt to refer to a different instance of DateTime. Under the hood, the DateTime.Now property generates a new DateTime instance every time you access it.

提交回复
热议问题