当前位置: 首页>>代码示例>>C#>>正文


C# GSM.AddACall方法代码示例

本文整理汇总了C#中GSM.AddACall方法的典型用法代码示例。如果您正苦于以下问题:C# GSM.AddACall方法的具体用法?C# GSM.AddACall怎么用?C# GSM.AddACall使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GSM的用法示例。


在下文中一共展示了GSM.AddACall方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CallHistoryTest

    //method for testing the calls
    public static void CallHistoryTest()
    {
        Console.WriteLine(new string('-', 30));
        Console.WriteLine("Phone calls test");

        //creates an instance of the GSM class
        var phone = new GSM("Lumia 1920", "Nokia");

        //adds calls
        phone.AddACall(new Call("0555 555 555", 120));
        phone.AddACall(new Call("0999 999 999", 153));
        phone.AddACall(new Call("0888 888 888", 305));

        //displays information about calls
        Console.WriteLine(new string('-', 30));
        Console.WriteLine("Calls added.");
        Console.WriteLine("Calls: ");
        foreach (var call in phone.CallHistory)
        {
            Console.WriteLine(call.ToString());
            Console.WriteLine();
        }

        //total price at 0.37 price per minute
        Console.WriteLine(new string('-', 30));
        var price = phone.CallPrice(0.37M);
        Console.WriteLine("Total price of the calls: {0:F2}", price);

        //finding longest call
        ulong longestCall = 0;
        foreach (var call in phone.CallHistory)
        {
            if (call.Duration > longestCall)
            {
                longestCall = call.Duration;
            }
        }
        Console.WriteLine(new string('-', 30));
        Console.WriteLine("Longest call: {0} seconds", longestCall);

        //removing longest call
        var longest = new Call("000", 000);
        foreach (var call in phone.CallHistory)
        {
            if (call.Duration == longestCall)
            {
                longest = call;
            }
        }
        phone.DeleteACall(longest);

        //calculate total price again
        Console.WriteLine(new string('-', 30));
        Console.WriteLine("After removing the longest call: ");
        price = phone.CallPrice(0.37M);
        Console.WriteLine("Total price of the calls: {0:F2}", price);

        //clear call history
        Console.WriteLine(new string('-', 30));
        Console.WriteLine("Clearing call history...");
        phone.ClearCallHistory();

        //print call history
        Console.WriteLine("Call history elements: {0}", phone.CallHistory.Count);
    }
开发者ID:Vyara,项目名称:Telerik-Academy,代码行数:66,代码来源:GSMCallHistoryTest.cs


注:本文中的GSM.AddACall方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。