按整数vs.日期时间排序 [英] Sort by Integer vs. by DateTime

查看:115
本文介绍了按整数vs.日期时间排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是从.NET的角度讲的,但这可以扩展到使用类似逻辑的其他语言或框架.

I'm speaking from the .NET point of view but this could extend to other languages or frameworks that use similar logic.

假设通过DateTime属性对对象进行排序时,出于比较目的,将DateTime值转换为Ticks(即长整数)是否正确?结果,按DateTime排序的速度是否比按整数排序的速度慢很多(如果有的话)?

Is it correct to assume that when sorting objects by a DateTime property, the DateTime value is converted to Ticks (i.e., long integers) for comparison purposes? And as a result, the speed of sorting by DateTime is not much, if any, slower than sorting by integers?

推荐答案

是的,它比较刻度线.这是实际的实现:

Yes, it compares ticks. Here is actual implementation:

public int CompareTo(DateTime value) {
    long valueTicks = value.InternalTicks; 
    long ticks = InternalTicks; 
    if (ticks > valueTicks) return 1;
    if (ticks < valueTicks) return -1; 
    return 0;
}

这篇关于按整数vs.日期时间排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆