Winform 积累

1.TimeSpan

  • 时间 1 是 2011-1-2 1:00:01;
  • 时间 2 是 2011-1-12 1:00:00。

用时间 2 减时间 1,得到一个 TimeSpan 实例。

那么时间 2 比时间 1 多 9 天 23 小时 59 分 59 秒。

那么,Days 就是 9,Hours 就是 23,Minutes 就是 59,Seconds 就是 59。

2.逻辑运算符

C#提供“与”和“或”逻辑运算符,他们能够产生更高效的代码。

在“与”运算符中(&&),如果第一个操作数为假,那么无需考虑第二个操作数,其结果都为假

在“或”运算符中(||),如果第一个操作数为真,那么无需考虑第二个操作数,其结果都为真

在这两种情况下,无需计算第二个操作数的值,产生高效代码

他们的常规样式“&”和“|”,常规样式总是计算每个操作数

注意:在某些情况下,会有副作用

//老梅

using System

class SideEffects
    {
        static void Main()
        {
            int i;
            bool someCondition = false;
            i = 0;
            // Here, i is still incremented even though the if statement fails.
            if (someCondition & (++i < 100))
                Console.WriteLine("this won't be displayed");
            Console.WriteLine("if statement executed: " + i); // displays 1
            // In this case, i is not incremented because the short-circuit
            // operator skips the increment.
            if (someCondition && (++i < 100))
                Console.WriteLine("this won't be displayed");
            Console.WriteLine("if statement executed: " + i); // still 1 !!
        }
    }

转载于:https://www.cnblogs.com/myblog_myf/archive/2010/12/29/1920669.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值