黑马程序员技术交流社区

标题: 应该在什么情况下使用索引? [打印本页]

作者: 黒■色    时间: 2014-4-13 01:45
标题: 应该在什么情况下使用索引?
本帖最后由 黒■色 于 2014-4-14 12:03 编辑

最好有实例啊!!!
作者: 鲤鱼    时间: 2014-4-13 01:55
http://msdn.microsoft.com/zh-cn/library/2549tw02.aspx
http://www.jobui.com/mianshiti/it/shujuku/5957/
http://bbs.csdn.net/topics/360112753

作者: 惊风侠    时间: 2014-4-13 16:52
数据量大的时候。。。
作者: 黒■色    时间: 2014-4-14 12:02
鲤鱼 发表于 2014-4-13 01:55
http://msdn.microsoft.com/zh-cn/library/2549tw02.aspx
http://www.jobui.com/mianshiti/it/shujuku/5957 ...

看完懂得差不多了 谢谢了
作者: 黒■色    时间: 2014-4-14 12:03
惊风侠 发表于 2014-4-13 16:52
数据量大的时候。。。

谢谢了!
作者: boy_AND_gou    时间: 2014-4-14 23:39
要查询的东西特别大,不能用一般的查询方式,这个时候使用索引方便很多!
作者: 袁晓俊    时间: 2014-4-15 21:35

索引器是一种成员,它使对象能够用与数组相同的方式进行索引。属性启用类似字段的访问,而索引器启用类似数组的访问。

例如,请看一下前面研究过的 Stack 类。该类的设计者可能想提供类似数组的访问,以便不必执行 Push 和 Pop 操作,就可以检查或改变堆栈上的各个项。也就是说,使 Stack 类既是链接表,又可像数组一样方便地对它进行访问。

索引器声明类似于属性声明,主要区别是索引器是无名称的(由于 this 被索引,因此在声明中使用的“名称”为 this),而且索引器包含索引参数。索引参数在方括号中提供。示例




using System;public class Stack{   private Node GetNode(int index) {      Node temp = first;       while (index > 0 && temp != null) {         temp = temp.Next;         index--;      }      if (index < 0 || temp == null)         throw new Exception("Index out of range.");      return temp;   }   public object this[int index] {      get {         return GetNode(index).Value;      }      set {         GetNode(index).Value = value;      }   }   ...}class Test{   static void Main() {      Stack s = new Stack();      s.Push(1);      s.Push(2);      s.Push(3);      s[0] = 33;   // Changes the top item from 3 to 33      s[1] = 22;   // Changes the middle item from 2 to 22      s[2] = 11;   // Changes the bottom item from 1 to 11   }}




作者: 鲤鱼    时间: 2014-4-17 16:01
{:3_68:}我不总结是因为自己还在学习也不知道答案,只好搜索下,万一自己总结错了,岂不是害人了。{:3_57:}不过我相信会有人纠正我的,对吧?




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2