当前位置: 首页 > news >正文

windows云桌面株洲seo优化官网

windows云桌面,株洲seo优化官网,个人账号密码网站建设,网站建设维保合同索引器允许类或者结构的实例按照与数组相同的方式进行索引取值#xff0c;索引器与属性类似#xff0c;不同的是索引器的访问是带参的。 索引器和数组比较#xff1a; (1)索引器的索引值(Index)类型不受限制 (2)索引器允许重载 (3)索引器不是一个变量 索引器和属性的不同点 …  索引器允许类或者结构的实例按照与数组相同的方式进行索引取值索引器与属性类似不同的是索引器的访问是带参的。 索引器和数组比较 (1)索引器的索引值(Index)类型不受限制 (2)索引器允许重载 (3)索引器不是一个变量 索引器和属性的不同点 (1)属性以名称来标识索引器以函数形式标识 (2)索引器可以被重载属性不可以 (3)索引器不能声明为static属性可以   一个简单的索引器例子 using System; using System.Collections; public class IndexerClass {private string[] name new string[2];//索引器必须以this关键字定义其实这个this就是类实例化之后的对象public string this[int index]{//实现索引器的get方法get{if (index 2){return name[index];}return null;}//实现索引器的set方法set{if (index 2){name[index] value;}}} } public class Test {static void Main(){//索引器的使用IndexerClass Indexer new IndexerClass();//“”号右边对索引器赋值其实就是调用其set方法Indexer[0] 张三;Indexer[1] 李四;//输出索引器的值其实就是调用其get方法Console.WriteLine(Indexer[0]);Console.WriteLine(Indexer[1]);} }  以字符串作为下标对索引器进行存取 public class IndexerClass {//用string作为索引器下标的时候要用Hashtableprivate Hashtable name new Hashtable();//索引器必须以this关键字定义其实这个this就是类实例化之后的对象public string this[string index]{get { return name[index].ToString(); set { name.Add(index, value); }} } public class Test {static void Main(){IndexerClass Indexer new IndexerClass();Indexer[A0001] 张三;Indexer[A0002] 李四;Console.WriteLine(Indexer[A0001]);Console.WriteLine(Indexer[A0002]);} }  索引器的重载 public class IndexerClass {private Hashtable name new Hashtable();//1通过key存取Valuespublic string this[int index]{get { return name[index].ToString(); }set { name.Add(index, value); }}//2通过Values存取keypublic int this[string aName]{get{//Hashtable中实际存放的是DictionaryEntry(字典)类型如果要遍历一个Hashtable就需要使用到DictionaryEntryforeach(DictionaryEntry d in name){if (d.Value.ToString() aName){return Convert.ToInt32(d.Key);}}return -1;}set{name.Add(value, aName);}} } public class Test {static void Main(){IndexerClass Indexer new IndexerClass();//第一种索引器的使用Indexer[1] 张三;//set访问器的使用Indexer[2] 李四;Console.WriteLine(编号为1的名字 Indexer[1]);//get访问器的使用Console.WriteLine(编号为2的名字 Indexer[2]);Console.WriteLine();//第二种索引器的使用Console.WriteLine(张三的编号是 Indexer[张三]);//get访问器的使用Console.WriteLine(李四的编号是 Indexer[李四]);Indexer[王五] 3;//set访问器的使用Console.WriteLine(王五的编号是 Indexer[王五]);} }  多参索引器 using System; using System.Collections;//入职信息类 public class EntrantInfo {//姓名、编号、部门private string name;private int number;private string department;public EntrantInfo(){}public EntrantInfo(string name, int num, string department){this.name name;this.number num;this.department department;}public string Name{get { return name; }set { name value; }}public int Num{get { return number; }set { number value; }}public string Department{get { return department; }set { department value; }} }//声明一个类EntrantInfo的索引器 public class IndexerForEntrantInfo {private ArrayList ArrLst;//用于存放EntrantInfo类public IndexerForEntrantInfo(){ArrLst new ArrayList();}//声明一个索引器以名字和编号查找存取部门信息public string this[string name, int num]{get{foreach (EntrantInfo en in ArrLst){if (en.Name name en.Num num){return en.Department;}}return null;}set{//new关键字C#规定实例化一个类或者调用类的构造函数时必须使用new关键ArrLst.Add(new EntrantInfo(name, num, value));}}//声明一个索引器以编号查找名字和部门public ArrayList this[int num]{get{ArrayList temp new ArrayList();foreach (EntrantInfo en in ArrLst){if (en.Num num){temp.Add(en);}}return temp;}}//还可以声明多个版本的索引器... }public class Test {static void Main(){IndexerForEntrantInfo Info new IndexerForEntrantInfo();//this[string name, int num]的使用Info[张三, 101] 人事部;Info[李四, 102] 行政部;Console.WriteLine(Info[张三, 101]);Console.WriteLine(Info[李四, 102]);Console.WriteLine();//this[int num]的使用foreach (EntrantInfo en in Info[102]){Console.WriteLine(en.Name);Console.WriteLine(en.Department);}} }     原文链接http://www.cnblogs.com/ArmyShen/archive/2012/08/27/2659405.html 转载于:https://www.cnblogs.com/Percy_Lee/p/5160131.html
http://www.zqtcl.cn/news/938391/

相关文章:

  • 怎么学做电子商务网站知果果网站谁做的
  • 网站软文推广网站wordpress建站教程第六节
  • 公司制作网站多少钱移动端网站建设的请示
  • 做网站 对方传销廊坊网站备案
  • 1688网站链接图片怎么做wordpress 饭店主题
  • 人事怎么做招聘网站比对分析教育机构网站开发
  • 抚顺市+网站建设做网站用apache还是nginx
  • 群晖ds216j能否做网站百度收录官网
  • 白银市建设局网站网站设计规划的一般流程
  • 佛山网站建设企划动力新兴县城乡建设局网站
  • 软件开发 网页设计网站网页游戏链接大全
  • 网站建设犭金手指a15做校园网站 怎么备案
  • 淘客网站怎么做排名百度指数里的资讯指数是什么
  • 泰州网站开发网站建设个可行性研究
  • 网站ipv6改造怎么做 网页代码网页游戏在线玩链接
  • 做网站和优化学校asp网站
  • 佛山正规网站建设哪家好合肥专业网站优化价格
  • 华容网站免费ppt模板下载医学类
  • 网站注册申请艺术风格网站
  • 怎么上国外购物网站网站毕业作品代做
  • wordpress 描述字段seo排名技术教程
  • 重庆seo网站建设wordpress评论邮件插件
  • 企业网站模板下载网站模板下载做一个购物商城网站多少钱
  • 网站开发有哪些服务推荐电子商务网站建设
  • 网站交互技术网站框架类型
  • 国内网站建设公司top20对软件开发的理解和认识
  • 一键生成网站前端开发用什么语言
  • pc 网站建设苏州seo网站诊断
  • 江苏盐城建筑公司网站seo专员的工作内容
  • 做网站内容腾讯云wordpress教程