提升查询和排序的效率

查询算法:普通查询,二分查询,插值查询,二叉树查询.
排序算法:冒泡排序,插入排序,希尔排序,快拍排序.
普通查询:for循环:

      例如: List<int> GetData()

       {
        str = new int[500 * 1024 * 3];
        List<int> list = new List<int>(5 * 1024 * 3);
        for (int i = 0; i < 5 * 1024 * 3; i++)
        {
          if (i < 5 * 1024)
          {
            list.Add(((i + 1) % 2) * (i + 1) / 3);
          }
          else if (i < 5 * 1024 * 2)
          {
            list.Add(i);
          }
          else
          {
             Random rand = new Random();
             list.Add(rand.Next(10000));
          }
        }
          return list;
       }
       List<int> list = p.GetData();

       Stopwatch sw = new Stopwatch();

         sw.Start();
         for (int i = 1; i < list.Count; i++)
       {
          if (list[i] == 153222)
          {
            Console.WriteLine(list[i]); // static 0.011 new 0.012
          }
       }
       sw.Stop();
       Console.WriteLine(sw.Elapsed);

    冒泡排序:
    例如:
      List<int> Swap(List<int> list, int i, int j)
      {
         int temp = list[i]; // 0
         list[i] = list[j]; // 0 = 1
           list[j] = temp; //
         return list;
      }
      private int privation(List<int> list, int low, int high)
      {
         int priotkey = list[low];
         while (low < high)
         {
            while (low < high && priotkey <= list[high])
            {
              high--;
            }
            Swap(list, low, high);
            while (low < high && priotkey >= list[low])
            {
                low++;
            }
            Swap(list, low, high);
        }
         return low;
      }
      排序 冒泡
      List<int> BulletSort(List<int> list)
      {
        for (int i = 0; i < list.Count; i++) // 1 3 6 4 8 9 3 10 52 80 6 0 793
        {
          for (int j = i + 1; j < list.Count; j++)
          {
            if (list[i] > list[j]) //1 > 0
            {
              Swap(list, i, j);
            }
          }
        }
        return list;
       }
      List<int> listsort = p.BulletSort(list); // 15000 1.29

    查找二分:
    static int Binary_Search(List<int> list, int n, int key)
    {
      int low, high, mid;
      low = 1;
      high = n;
      while (low < high)
      {
        mid = (low + high) / 2;

        if (key < list[mid])
        {
          high = mid - 1;
        }
        else if (key > list[mid])
        {
          low = mid + 1;
        }
        else
        {
          return list[mid];
        }
      }
      return 0;
    }

    List<int> listsort1 = p.QuickSort(list, 0, list.Count - 1); // 15000 0.13
    Console.WriteLine(Binary_Search(listsort1, listsort1.Count, 652)); // 15000 0.18

    快排:

      List<int> QuickSort(List<int> list, int low, int high) // 0 15359
      {
        int priot;
        if (low < high)
        {
          priot = privation(list, low, high);
          QuickSort(list, low, priot - 1);
          QuickSort(list, priot + 1, high);
        }
        return list;
      }
      List<int> listsort1 = p.QuickSort(list, 0, list.Count - 1); // 15000 0.13

两种用于非泛型集合:
    (1)转换类cast():将对象转换成泛型(返回可被枚举的对象)或规定类型.
          mscorlib核心技术-->system.collections集合.
          enqueue(object)-->将对象添加到system.collections.queue的结尾处.
          dequeue-->移除并返回位于system.collections.queue开始出的对象.
          stack-->后进先出,堆载型成(表示对象的简单的后进先出非泛型集合).
     (2)dt.rows.asqueryable将对象转换成泛型或规定类型.

文本文件查询:File.ReadAllLines("文件名") where !line.startswith("#");-->舍弃第一行
       Let parts=line.split(',') select new {};
       注释:Let相当于into.

设计模式:ForEach操作符=>相当于select投影到另一个对象,传统的ForEach只是迭代,而foreach操作符可以对源序列中的每个元素进行遍历并执行某一传统操作.

分页(分区):skip跳过多少条数据.take取多少数据.

序列:IEnumberable.Range()--->生成指定范围内连续的整数的序列.

ORM工具---->object relation mapping映射,
       partial=>这个关键字表示分布类-->Model-->ADO.NET-->DataSet-->List<T>-->增删查改(ADO.NET实体数据模型)-->EF框架.
返回一条元素:single()方法和first().
savechanges()相当于commit().

非托管资源:database(数据库)需释放资源,EF实体框架,office(com对象),gdi(绘图).
扩展管理器--->联机库更新--->NUGet(程序表管理器).

EF框架由三种内容构成:(1)SSDL Content储存数据模型(偏向数据库).
            (2)CSDL Content结构定义模型(偏向程序实体模型).
                              (3)C-S Mapping content储存结构映射模型(关联).

原文地址:https://www.cnblogs.com/ranfang/p/3519283.html