一段时间以来,我一直在寻找答案,但实际上我无处可寻。
我特别关注 this page .那里说 CompareTo
方法返回一个整数,指示它是更早、相同还是更晚。我理解它的用法,我知道在早期整数是负数,同样是 0 等等。
但是这个整数是多少?它会以秒、毫秒、刻度为单位返回差异,还是什么都不返回?我希望你能帮我解决这个问题,如果有人能找到另一个有这个问题的帖子,请告诉我。老实说,我很惊讶我无法立即找到关于这个主题的问题......
最佳答案
文档其实在IComparable接口(interface)页面(即DateTime实现): http://msdn.microsoft.com/en-us/library/system.icomparable.aspx
The implementation of the CompareTo(Object) method must return an Int32 that has one of three values, as shown in the following table.
Less than zero: The current instance precedes the object specified by the CompareTo method in the sort order.
Zero: This current instance occurs in the same position in the sort order as the object specified by the CompareTo method.
Greater than zero: This current instance follows the object specified by the CompareTo method in the sort order.
关于c# - DateTime.CompareTo 实际返回什么整数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13668985/