Beispiel #1
0
        static void Main(string[] args)
        {
            Caculate calc = Add;

            Console.WriteLine(calc(3, 4));

            calc = Multiply;
            Console.WriteLine(calc(3, 4));

            Console.Read();
        }
Beispiel #2
0
        public void AddNum_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            var unitUnderTest = new Caculate();
            int a             = 1;
            int b             = 2;
            int expected      = 3;
            int actual;

            // Act
            actual = unitUnderTest.AddNum(a, b);


            // Assert
            Assert.AreEqual(expected, actual);
        }
Beispiel #3
0
        private void btn2_Click(object sender, EventArgs e)
        {
            Caculate a = One;
            //实例化委托
            //var m = new Caculate(One);

            //调用
            var    result = a.BeginInvoke(10, null, null);
            string msg    = "正在计算,请稍等...";

            this.lblname1.Text = msg;
            this.lblname2.Text = Two(50).ToString();


            var a1 = a.EndInvoke(result);

            this.lblname1.Text = a1.ToString();
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            Caculate cac    = new Caculate();
            string   str    = "";
            string   result = "";

            Console.WriteLine("请输入第一个字符串");
            cac.m  = Console.ReadLine();
            str    = cac.m;
            result = System.Text.RegularExpressions.Regex.Replace(str, @"[0-9]+", "");
            if (string.IsNullOrEmpty(result))
            {
                cac.x = Convert.ToInt32(str);
                Console.WriteLine("请输入符号");
                cac.symbol = char.Parse(Console.ReadLine());
                Console.WriteLine("请输入第二个字符串");
                cac.z = Console.ReadLine();
                str   = cac.z;
                for (int i = 0; i < str.Length; i++)
                {
                    result = System.Text.RegularExpressions.Regex.Replace(str, @"[0-9]", " ");
                }
                if (!string.IsNullOrEmpty(result))
                {
                    cac.y = Convert.ToInt32(str);
                    Console.WriteLine("计算结果是{0}", cac.Cac(cac.x, cac.y));
                }
                else
                {
                    Console.WriteLine("计算结果是{0}", cac.Cac(ref cac.m, ref cac.z));
                }
            }
            else
            {
                Console.WriteLine("请输入符号");
                cac.symbol = char.Parse(Console.ReadLine());
                Console.WriteLine("请输入第二个字符串");
                cac.z = Console.ReadLine();
                Console.WriteLine("计算结果是{0}", cac.Cac(ref cac.m, ref cac.z));
            }
        }