c# - DateTime.CompareTo 实际返回什么整数?

标签 c# datetime compareto

一段时间以来,我一直在寻找答案,但实际上我无处可寻。

我特别关注 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/

相关文章:

c# - 删除 DateTime.ParseExact 的时区

python - 字符串和日期时间对象互换

java - 为 Hadoop 实现 WritableComparable

java - 处理比较器的最佳实践

c# - 在 iPhone 中获取重复电话号码的理想方法是什么 - MonoTouch

c# - 如何在 MVC C# 网站中识别我的主页是从哪里加载的(即调用 URL)

arrays - 在vuejs中正确显示 "created_at"字段

java - 使用 compareTo() 方法按字母顺序对列表进行排序

c# - 如何使用 XAML 资源作为 Mahapps.Metro 标题栏中的图标?

c# - WPF 绑定(bind)不更新 View