阅读这篇博客文章后:http://wekeroad.com/post/4069048840/when-should-a-method-be-a-property,
我不知道为什么微软在C#中进行选择:
DateTime的ADT = DateTime.Now;
而不是
DateTime的ADT = DateTime.Now();
的最佳做法说:连续两次调用该成员时,使用的方法会产生不同的结果
和 DateTime.Now
就是非determistic方法/属性很好的例子。
你知道,如果有任何原因的设计? 或者,如果它只是一个小错误?
解决方案我相信通过C#CLR,杰弗里里希特提到DateTime.Now是一个错误。
本的System.DateTime类有一个只读 现在属性,返回当前的日期和时间。每次查询这个时候 属性,它会返回一个不同的值。这是一个错误,而微软祝愿 他们可以通过现在的方法,而不是一个属性的修复类。
通过C#第3版CLR - 第243
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# :
DateTime aDt = DateTime.Now;
instead of
DateTime aDt = DateTime.Now();
Best practices say : Use a method when calling the member twice in succession produces different results
And DateTime.Now
is perfect example of non-determistic method/property.
Do you know if there any reason for that design ? Or if it's just a small mistake ?
解决方案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
相关推荐
最新文章