static void NotMain()
        {
            MyBol      Bol   = (x, y) => x == y;
            MyBol_2    Bol_2 = (x, s) => s.Length > x;
            calculator C     = (X, Y) => X * Y;
            VS         S     = () => Console.Write("我是无参数Labada表达式");

            //
            int[] numbers    = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
            int   oddNumbers = numbers.Count(n => n % 2 == 1);
            //
            List <People> people = LoadData();//初始化

            // 分解
            // 自己建的委托 delegate bool MyDele(People p);
            // 使用委托
            MyDele myDele = p => p.age > 20;
            // C#内置泛型委托  delegate TResult System.Func<int T, out TResult>(T arg)
            Func <People, bool> predicate = p => p.age > 20;

            IEnumerable <People> results2 = people.Where(predicate);

            // 委托的实例化:使用匿名方法
            // < 委托类型 > < 实例化名 >= delegate (< 函数参数 >){ 函数体};
            Func <People, bool>  predicate2 = delegate(People p) { return(p.age > 20); };
            IEnumerable <People> results4   = people.Where(predicate2);

            IEnumerable <People> results = people.Where(delegate(People p) { return(p.age > 20); });
            // 更简便的写法
            IEnumerable <People> results3 = people.Where(p => p.age > 20);
        }
Beispiel #2
0
        public void CalcAddMethod()
        {
            calculator add = new calculator();

            result = add.Add(10, 20);
            Assert.AreEqual(30, result);
        }
        static void NotMain()
        {
            calculator cal = new calculator(Adding);
            int        He  = cal(1, 1);

            Console.Write(He);
        }
Beispiel #4
0
        public void SubtractionTest_PositiveInteger_Equal()
        {
            var calc   = new calculator();
            var result = calc.Subtract(5, 1);

            Assert.AreEqual(4, result);
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            calculator culc = new calculator();

            //--- Add logers
            ConsoleLogger cLogger = new ConsoleLogger();
            culc.OperationCompleted += cLogger.Log;
            culc.OperationFailed += cLogger.Log;

            FileLogger fLogger = new FileLogger(@"D:\LogFile.log");
            culc.OperationCompleted += fLogger.Log;
            culc.OperationFailed += fLogger.Log;
            //----------------------------------------------------

            string operation = string.Empty;
            string arg1 = string.Empty;
            string arg2 = string.Empty;
            Console.WriteLine("Enter argument 1:\r\n");
            arg1 = Console.ReadLine();
            Console.WriteLine("Enter argument 2:\r\n");
            arg2 = Console.ReadLine();
            Console.WriteLine("Enter operation(+,-,*,/):\r\n");
            operation = Console.ReadLine();

            culc.DoOperation(operation, arg1, arg2);

            Console.ReadLine();
        }
Beispiel #6
0
        public void AdditionAccumulatorInit_NegativeInteger_Equal()
        {
            var calc       = new calculator();
            var calculated = calc.Add(-4);

            Assert.AreEqual(-4, calculated);
        }
Beispiel #7
0
        public void AdditionTest_NegativeInteger_NotEqual()
        {
            var calc       = new calculator();
            var calculated = calc.Add(-4, -4);

            Assert.AreNotEqual(8, calculated);
        }
Beispiel #8
0
        public void Power_PosIntegerAndExponentDecimal_Equal()
        {
            var uut = new calculator();
            var ans = uut.Power(1, 2);

            Assert.That(1, Is.EqualTo(ans));
        }
Beispiel #9
0
        public void AdditionTest_PositiveInteger_Equal()
        {
            var calc   = new calculator();
            var result = calc.Add(3, 5);

            Assert.AreEqual(8, result);
        }
Beispiel #10
0
        public void Divide_NonZero_Equal()
        {
            var uut = new calculator();
            var ans = uut.Divide(6, 2);

            Assert.AreEqual(3, ans);
        }
Beispiel #11
0
        public void DivisionAccumulator_ZeroInteger_EqualThrow()
        {
            var calc = new calculator();

            calc.Add(6);
            Assert.Catch <DivideByZeroException>(() => calc.Divide(0));
        }
Beispiel #12
0
        public void SubtractionTest_NegativeInteger_Equal()
        {
            var calc   = new calculator();
            var result = calc.Subtract(-5, -2);

            Assert.AreEqual(-3, result);
        }
Beispiel #13
0
        public void SubtractionTest_PositiveAndNegativInteger_Equal()
        {
            var calc       = new calculator();
            var calculated = calc.Subtract(-4, 8);

            Assert.AreEqual(-12, calculated);
        }
Beispiel #14
0
        // 1,委托使用
        public static void DelTest(int a, int b)
        {
            calculator cal = new calculator(Adding);
            int        num = cal(a, b);

            Console.WriteLine(num);
        }
        public static void Main()
        {
            Program p = new Program();

            addnum ad = new addnum(p.add);
            int    a  = ad(10, 20); //ad.Invoke(10,20)
            //Console.WriteLine(a);


            subnum sb = new subnum(p.sub);

            // Console.WriteLine(  sb(10,20));


            calculator c   = new calculator(p.add);
            int        ans = c.Invoke(12, 23);

            Console.WriteLine(ans);
            c = c + p.sub;
            int ans2 = c.Invoke(1, 1);

            Console.WriteLine(ans2);

            //multicast delegate
            rectDelegate rd = new rectDelegate(p.area);

            rd += p.perimeter;
            rd.Invoke(10, 4);
        }
Beispiel #16
0
        // 3,lamda表达式
        public static void LamdaTest(int a, int b)
        {
            calculator cal = (x, y) => x + y;
            int        num = cal(a, b);

            Console.WriteLine(num);
        }
Beispiel #17
0
    static void Main(String[] args)
    {
        calculator calc = new calculator();

        //calc.set(33,3);
        calc.Add();
    }
Beispiel #18
0
        public void PowerAccumulator_NegativeAndPositiveDouble_EqualThrow()
        {
            var calc = new calculator();

            calc.Add(-0.5);
            Assert.Catch <ArithmeticException>(() => calc.Power(0.5));
        }
Beispiel #19
0
        public void MultiplyAccumulatorTest_OneInteger_Equal()
        {
            var calc       = new calculator();
            var calculated = calc.Multiply(6.4);

            Assert.AreEqual(0, calculated);
        }
Beispiel #20
0
        public void MultiplyTest_PositiveInteger_Equal(double first, double second, double expectedresult)
        {
            var calc       = new calculator();
            var calculated = calc.Multiply(first, second);

            Assert.AreEqual(expectedresult, calculated);
        }
Beispiel #21
0
        public void MultiplyTest_NegativeInteger_Equal()
        {
            var calc       = new calculator();
            var calculated = calc.Multiply(-6, 3);

            Assert.AreEqual(-18, calculated);
        }
Beispiel #22
0
        static void Main()
        {
            calculator sum = (x, y) => x + y;//Lambda表达式

            Console.WriteLine(sum(1, 2));
            Console.ReadLine();
        }
Beispiel #23
0
        public void Power_PositiveInteger_Equal()
        {
            var calc       = new calculator();
            var calculated = calc.Power(4, 2);

            Assert.AreEqual(16, calculated);
        }
Beispiel #24
0
 public MainWindow()//默认从这个入口进入
 {
     InitializeComponent();
     c = new calculator();
     textBox.Clear();
     currExpression = "";
 }
Beispiel #25
0
        public void AdditionTest_PositiveAndNegativInteger_Equal()
        {
            var calc       = new calculator();
            var calculated = calc.Add(-4, 8);

            Assert.AreEqual(4, calculated);
        }
Beispiel #26
0
        public void calculatorAddMethod(int x, int y, int z)
        {
            calculator add = new calculator();

            result = add.Add(x, y);
            Assert.AreEqual(z, result);
        }
Beispiel #27
0
        public void MultiplyTest_ZeroInteger_Equal()
        {
            var calc       = new calculator();
            var calculated = calc.Multiply(6.4, 0);

            Assert.AreEqual(0, calculated);
        }
Beispiel #28
0
    static void Main(String[] args)
    {
        calculator cal    = new calculator();
        int        number = 6;

        cal.addone(ref number);
        Console.WriteLine("\n\t\t\t Number={0}", number);
    }
Beispiel #29
0
        public void ClearAccumulator_Equal()
        {
            var calc = new calculator();

            calc.Add(420);
            calc.Clear();
            Assert.AreEqual(0, calc.Accumulator);
        }
Beispiel #30
0
        public void test_first_test(int a, int b, int exp)
        {
            calculator temp   = new calculator();
            int        actual = temp.add(a, b);
            int        expect = exp;

            Assert.AreEqual(actual, expect);
        }
Beispiel #31
0
        public void PowerAccumulator_NegativeAndPositiveInteger_Equal()
        {
            var calc       = new calculator();
            var calculated = calc.Add(-4);

            calculated = calc.Power(8);
            Assert.AreEqual(65536, calculated);
        }
Beispiel #32
0
 static void Main(string[] args)
 {
     int year, month, day, days;
     Console.WriteLine("写出年和月份和日期");
     string s_month, s_day, s_year, s_days;
     s_year = Console.ReadLine();
     s_month = Console.ReadLine();
     s_day = Console.ReadLine();
     year = Convert.ToUInt16(s_year);
     month = Convert.ToUInt16(s_month);
     day = Convert.ToUInt16(s_day);
     calculator cal1 = new calculator();
     days = cal1.countday(year, month, day);
     s_days = Convert.ToString(days);
     Console.WriteLine(s_days);
     Console.ReadLine();
 }
        public ActionResult Index(calculator cal,string sign)
        {
            CalculatorRef.calculatorSoapClient client = new CalculatorRef.calculatorSoapClient();
            switch (sign)
            {
                case "+":
                    cal.sum= client.Add(cal.firstNumber, cal.lastNumber);
                    break;
                case "-":
                    cal.sum = client.Substract(cal.firstNumber, cal.lastNumber);
                    break;
                case "*":
                    cal.sum = client.Multiple(cal.firstNumber, cal.lastNumber);
                    break;
                case "/":
                    cal.sum = client.Divide(cal.firstNumber, cal.lastNumber);
                    break;

            }
            return View(cal);
        }
Beispiel #34
0
        static void Main(string[] args)
        {
            myUtil myUtilObject = new myUtil();

            int i, j;
            calculator addnumbers = new calculator(myUtilObject.addMethod);
            calculator subnumbers = new calculator(myUtilObject.subMethod);

            Console.Write("enter addnumbers number:");
            i = int.Parse(Console.ReadLine());

            Console.Write("enter addnumbers number:");
            j = int.Parse(Console.ReadLine());

            addnumbers(i, j);
            subnumbers(i, j);

            Console.Write("\nadding two values: " + addnumbers(i,j));
            Console.Write("\nsubtracting two values: " + addnumbers(i, j));

            Console.Read();
        }