コード例 #1
0
ファイル: Program.cs プロジェクト: kpgetcha/robot
        public Result ExecuteLogic(List <int> list, bool IsAcending)
        {
            if (_chip == null)
            {
                return(null);
            }

            if (_chip.GetType() == typeof(MySortChip))
            {
                MySortChip sortChip = (MySortChip)_chip;
                sortChip.Work(list, IsAcending);
                Result result = new Result();
                result.type        = ResultType.SORT;
                result.sortedArray = list.ToArray();
                return(result);
            }
            else if (_chip.GetType() == typeof(MySumChip))
            {
                MySumChip sumChip = (MySumChip)_chip;
                Result    result  = new Result();
                result.type = ResultType.SUM;
                result.sum  = sumChip.Work(list);
                return(result);
            }

            return(null);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: kpgetcha/robot
        static void Main(string[] args)
        {
            Robot robot    = new Robot();
            Chip  sortChip = new MySortChip();

            robot.AddChip(sortChip);
            List <int> list = new List <int>();

            list.Add(5);
            list.Add(3);
            list.Add(4);
            //executing to sort the list
            Console.WriteLine("number of unique chips currently: " + robot.Chipcount);
            Result result  = robot.ExecuteLogic(list, true);
            Chip   sumChip = new MySumChip();

            robot.AddChip(sumChip);
            result = robot.ExecuteLogic(list, false);
            Console.WriteLine("number of unique chips currently: " + robot.Chipcount);
            Console.Read();
        }