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


C# MyClass.Multiply方法代码示例

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


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

示例1: Main

    static void Main(string[] args)
    {
        MyClass oMyClass = new MyClass();

        bool bRun = true;
        int iInput;
        while (bRun)
        {
            Console.Clear();
            Console.WriteLine("What would you like to do?\n");

            Console.WriteLine("1. Add");
            Console.WriteLine("2. Subtract");
            Console.WriteLine("3. Multiply");
            Console.WriteLine("4. Divide");
            Console.WriteLine("5. Exit");

            Console.SetCursorPosition(0, 10);
            Console.Write(">> ");

            iInput = Console.Read();
            Console.ReadLine();

            if (iInput == '5')
                bRun = false;
            else
            {
                int iNum1 = 0, iNum2 = 0;

                bool bException = false;
                do
                {
                    Console.Clear();
                    Console.Write("Enter the first number");

                    Console.SetCursorPosition(0, 10);
                    Console.Write(">> ");

                    bException = false;
                    try { iNum1 = Convert.ToInt32(Console.ReadLine()); }
                    catch (FormatException)
                    {
                        Console.Write("Numbers only. Please try again...");
                        while (Console.ReadLine() != "") ;
                        bException = true;
                    }
                } while (bException);

                do
                {
                    Console.Clear();
                    Console.Write("Enter the second number");

                    Console.SetCursorPosition(0, 10);
                    Console.Write(">> ");

                    bException = false;
                    try { iNum2 = Convert.ToInt32(Console.ReadLine()); }
                    catch (FormatException)
                    {
                        Console.Write("Numbers only. Please try again...");
                        bException = true;
                    }
                } while (bException);
                switch (iInput)
                {
                    case '1':
                        {
                            int iDiff = oMyClass.Subtract(iNum1, iNum2);
                            Console.Write("{0} + {1} = {2}", iNum1, iNum2, iDiff);

                            Console.SetCursorPosition(0, 24);
                            Console.Write("Press Enter to Continue...");
                            while (Console.ReadLine() != "") ;
                        }
                        break;
                    case '2':
                        {
                            int iSum = oMyClass.Subtract(iNum1, iNum2);
                            Console.Write("{0} - {1} = {2}", iNum1, iNum2, iSum);

                            Console.SetCursorPosition(0, 24);
                            Console.Write("Press Enter to Continue...");
                            while (Console.ReadLine() != "") ;
                        }
                        break;
                    case '3':
                        {
                            int iProd = oMyClass.Multiply(iNum1, iNum2);
                            Console.Write("{0} * {1} = {2}", iNum1, iNum2, iProd);

                            Console.SetCursorPosition(0, 24);
                            Console.Write("Press Enter to Continue...");
                            while (Console.ReadLine() != "") ;
                        }
                        break;
                    case '4':
                        {
                            int iQuo = oMyClass.Divide(iNum1, iNum2);
                            Console.Write("{0} / {1} = {2}", iNum1, iNum2, iQuo);
//.........这里部分代码省略.........
开发者ID:bennybroseph,项目名称:Homework,代码行数:101,代码来源:Program.cs


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