Why is DateTime.Now a property and not a method?

后端 未结 6 1286
眼角桃花
眼角桃花 2020-12-08 13:06

After reading this blog entry : http://wekeroad.com/post/4069048840/when-should-a-method-be-a-property,

I\'m wondering why Microsoft choose in C# :

D         


        
6条回答
  •  清歌不尽
    2020-12-08 13:48

    I believe in CLR via C#, Jeffrey Richter mentions that DateTime.Now is a mistake.

    The System.DateTime class has a readonly Now property that returns the current date and time. Each time you query this property, it will return a different value. This is a mistake, and Microsoft wishes that they could fix the class by making Now a method instead of a property.

    CLR via C# 3rd Edition - Page 243

提交回复
热议问题