C# 设计模式系列教程-策略模式

2019-12-30 12:49:38于海丽


 public class Program
 {
  public static void Main(Object[] args)
  {
   int[] array = new int[] { 12, 8, 9, 18, 22 };

   //使用冒泡排序算法进行排序
   SortStratege sortStratege = new BubbleSort();
   SortContext sorter = new SortContext(array, sortStratege);
   int[] result = sorter.Sort();

   //使用插入排序算法进行排序
   SortStratege sortStratege2 = new InsertSort();
   SortContext sorter2 = new SortContext(array, sortStratege2);
   int[] result2 = sorter.Sort();
  }
 }

以上就是本文的全部内容,希望能给大家一个参考,也希望大家多多支持ASPKU。



注:相关教程知识阅读请移步到c#教程频道。