當前位置: 首頁>>代碼示例>>C#>>正文


C# Duration.Divide方法代碼示例

本文整理匯總了C#中System.Duration.Divide方法的典型用法代碼示例。如果您正苦於以下問題:C# Duration.Divide方法的具體用法?C# Duration.Divide怎麽用?C# Duration.Divide使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Duration的用法示例。


在下文中一共展示了Duration.Divide方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: TestDivisionByConstant

        public void TestDivisionByConstant()
        {
            Duration duration = new Duration(500, 100.0);
            Duration result = duration.Divide(100.0);
            Assert.IsTrue(result.EqualsEpsilon(new Duration(5, 1.0), Constants.Epsilon10));
            result = duration / 100.0;
            Assert.IsTrue(result.EqualsEpsilon(new Duration(5, 1.0), Constants.Epsilon10));

            duration = new Duration(5, 68010.0);
            result = duration.Divide(100.0);
            Assert.IsTrue(result.EqualsEpsilon(new Duration(0, 5000.1), Constants.Epsilon10));
            result = duration / 100.0;
            Assert.IsTrue(result.EqualsEpsilon(new Duration(0, 5000.1), Constants.Epsilon10));

            duration = new Duration(0, 64800.0);
            result = duration.Divide(0.5);
            Assert.IsTrue(result.EqualsEpsilon(new Duration(1, 43200.0), Constants.Epsilon10));
            result = duration / 0.5;
            Assert.IsTrue(result.EqualsEpsilon(new Duration(1, 43200.0), Constants.Epsilon10));

            duration = new Duration(502, 43300.5);
            result = duration.Divide(100.5);
            Assert.IsTrue(result.EqualsEpsilon(new Duration(5, 1.0), Constants.Epsilon10));
            result = duration / 100.5;
            Assert.IsTrue(result.EqualsEpsilon(new Duration(5, 1.0), Constants.Epsilon10));

            duration = new Duration(5, 1.0);
            result = duration / -2.0;
            Assert.IsTrue(result.EqualsEpsilon(new Duration(-2, -43200.5), Constants.Epsilon10));

            duration = new Duration(0, 18 * 3600);
            result = duration / -0.5;
            Assert.AreEqual(-12 * 3600, result.Seconds);
            Assert.AreEqual(-1, result.Days);

            duration = new Duration(1, 4 * 3600);
            result = duration / -2;
            Assert.AreEqual(-14 * 3600, result.Seconds);
            Assert.AreEqual(0, result.Days);
        }
開發者ID:slojo404,項目名稱:czml-writer,代碼行數:40,代碼來源:TestDuration.cs

示例2: TestDivisionByDuration

        public void TestDivisionByDuration()
        {
            Duration one = new Duration(1, 0.0);
            Duration two = new Duration(0, 60.0);
            Assert.AreEqual(86400.0 / 60.0, one.Divide(two), Constants.Epsilon10);
            Assert.AreEqual(60 / 86400.0, two / one, Constants.Epsilon10);

            Duration three = new Duration(1, 43200.0);
            Assert.AreEqual((86400 + 43200) / 60.0, three / two, Constants.Epsilon10);
            Assert.AreEqual(60.0 / (86400.0 + 43200.0), two.Divide(three), Constants.Epsilon10);

            Duration four = new Duration(1, 0);
            Duration five = new Duration(0, -3600);
            Assert.AreEqual(-24, four / five, Constants.Epsilon10);
            Assert.AreEqual((-1.0 / 24.0), five / four, Constants.Epsilon10);

            Duration six = new Duration(-2, 0);
            Assert.AreEqual(-0.5, four / six);
            Assert.AreEqual(48, six / five);

            Duration seven = new Duration(0, -0.5);
            Assert.AreEqual(-48*3600, four / seven);
        }
開發者ID:slojo404,項目名稱:czml-writer,代碼行數:23,代碼來源:TestDuration.cs


注:本文中的System.Duration.Divide方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。