Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            ScoreOperation operation;                          //针对抽象目标接口编程

            operation = new OperationAdapter();                //读取配置文件,反射生成对象
            int[] scores = { 84, 76, 50, 69, 90, 91, 88, 96 }; //定义成绩数组
            int[] result;
            int   score;

            Console.WriteLine("成绩排序结果:");
            result = operation.sort(scores);

            //遍历输出成绩
            foreach (int i in scores)
            {
                Console.WriteLine(i + ",");
            }
            Console.WriteLine();

            Console.WriteLine("查找成绩90:");
            score = operation.search(result, 90);
            if (score != -1)
            {
                Console.WriteLine("找到成绩90。");
            }
            else
            {
                Console.WriteLine("没有找到成绩90。");
            }

            Console.WriteLine("查找成绩92:");
            score = operation.search(result, 92);
            if (score != -1)
            {
                Console.WriteLine("找到成绩92。");
            }
            else
            {
                Console.WriteLine("没有找到成绩92。");
            }
            Console.ReadKey();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            IScoreOperation scoreOperation = new OperationAdapter();

            int[] scores = { 84, 76, 50, 69, 90, 91, 88, 96 };
            int[] result;
            int   score;

            Console.WriteLine("测试成绩排序结果:");
            result = scoreOperation.Sort(scores);
            foreach (int s in result)
            {
                Console.Write("{0},", s.ToString());
            }
            Console.WriteLine();
            Console.WriteLine("查找是否有90分的人:");
            score = scoreOperation.Search(scores, 90);
            if (score == -1)
            {
                Console.WriteLine("抱歉,这个真没找到~~~");
            }
            else
            {
                Console.WriteLine("恭喜,的确存在90分选手~~~");
            }

            Console.WriteLine("查找是否有92分的人:");
            score = scoreOperation.Search(scores, 92);
            if (score == -1)
            {
                Console.WriteLine("抱歉,这个真没找到~~~");
            }
            else
            {
                Console.WriteLine("恭喜,的确存在92分选手~~~");
            }

            Console.ReadKey();
        }