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

用html5制作个人网站移动网站优化排名

用html5制作个人网站,移动网站优化排名,网站设计 知识产权,陕西今日头条新闻1、索引器定义 什么是索引器 索引器(indexer)是这样一种成员:它使对象能够用与数组相同的方式(即使用下标)进行索引 索引器的声明参见 C# 语言定义文档注意:没有静态索引器 索引器是一组 get 和 set 访问…

1、索引器定义

什么是索引器

  • 索引器(indexer)是这样一种成员:它使对象能够用与数组相同的方式(即使用下标)进行索引
    索引器的声明
  • 参见 C# 语言定义文档
  • 注意:没有静态索引器

索引器是一组 get 和 set 访问器,与属性类似:

  • 和属性一样,索引器不用分配内存来存储
  • 索引器和属性都主要来访问其他数据成员,它们与这些成员关联,并为它们提供获取和设置访问。
  • 属性通常表示单个数据成员
  • 索引器通常表示多个数据成员

注意:

  • 索引器总是实例成员,因此不能被声明为 static。

索引器的特点:

  • 索引器的索引值(Index)类型不受限制
  • 索引器允许重载
  • 索引器不是一个变量

请添加图片描述

2、索引器代码例子

(1)代码例子:采用字典方式

 class Program{static void Main(string[] args){Student stu = new Student();stu["Math"] = 90;var mathScore = stu["Math"];Console.WriteLine(mathScore);}}class Student{private int age;public int Age{get { return age; }set { age = value; }}private Dictionary<string, int> scoreDictionary = new Dictionary<string, int>();public int? this[string subject]{get{if(this.scoreDictionary.ContainsKey(subject)){return this.scoreDictionary[subject];}else{return null;}}set{if (value.HasValue == false){throw new Exception("Score cannot be null.");}if(this.scoreDictionary.ContainsKey(subject)){this.scoreDictionary[subject] = value.Value;//value 为可空类型}else{this.scoreDictionary.Add(subject, value.Value);}}}}

(2)代码例子:采用索引值方式
以下所有例子都来源于:# 索引器的多个例子及重载

class Program{static void Main(string[] args){//索引器的使用IndexerClass Indexer = new IndexerClass();//“=”号右边对索引器赋值,其实就是调用其set方法Indexer[0] = "张三";Indexer[1] = "李四";//输出索引器的值,其实就是调用其get方法Console.WriteLine(Indexer[0]);Console.WriteLine(Indexer[1]);Console.ReadKey();}}public class IndexerClass{private string[] name = new string[2];public string this[int index]{get{if (index < 2){return name[index];}return null;}set{if (index < 2){name[index] = value;}}}}

(3)代码例子:采用字符串为下标方式

    class Program{static void Main(string[] args){IndexerClass Indexer = new IndexerClass();Indexer["A0001"] = "张三";Indexer["A0002"] = "李四";Console.WriteLine(Indexer["A0001"]);Console.WriteLine(Indexer["A0002"]);Console.ReadKey();}}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); }}}

3、索引器重载

 class Program{static void Main(string[] args){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["王五"]);Console.ReadKey();}}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);}}}

4、多参索引器

   //入职信息类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;}}//还可以声明多个版本的索引器...}class Program{static void Main(string[] args){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);}Console.ReadKey();}}

文章转载自:
http://dinncoatrociously.knnc.cn
http://dinncozikkurat.knnc.cn
http://dinncoesemplastic.knnc.cn
http://dinncoequitable.knnc.cn
http://dinncopicksome.knnc.cn
http://dinncoacetate.knnc.cn
http://dinncoposit.knnc.cn
http://dinncoheadlike.knnc.cn
http://dinncojrmp.knnc.cn
http://dinncopinkster.knnc.cn
http://dinncoenate.knnc.cn
http://dinncowyse.knnc.cn
http://dinncohuanghai.knnc.cn
http://dinncoplantimal.knnc.cn
http://dinncoesperanto.knnc.cn
http://dinncocircs.knnc.cn
http://dinncoragnarok.knnc.cn
http://dinncoimpenitence.knnc.cn
http://dinncobufflehead.knnc.cn
http://dinnconobleite.knnc.cn
http://dinncouneducated.knnc.cn
http://dinncolucretia.knnc.cn
http://dinncovascula.knnc.cn
http://dinncocospar.knnc.cn
http://dinncosplenetical.knnc.cn
http://dinncochemiluminescence.knnc.cn
http://dinncoelectrohemostasis.knnc.cn
http://dinncogreyly.knnc.cn
http://dinncoisomorphic.knnc.cn
http://dinncoindivertible.knnc.cn
http://dinncoundereaten.knnc.cn
http://dinncoaccomplished.knnc.cn
http://dinncomicroscopium.knnc.cn
http://dinncoemployment.knnc.cn
http://dinncoplantmilk.knnc.cn
http://dinncomenstrua.knnc.cn
http://dinncophotog.knnc.cn
http://dinncocongregationalist.knnc.cn
http://dinncoutopianism.knnc.cn
http://dinncocoinstitutional.knnc.cn
http://dinncochino.knnc.cn
http://dinncospandy.knnc.cn
http://dinncoswept.knnc.cn
http://dinncopromptitude.knnc.cn
http://dinncotell.knnc.cn
http://dinncomeloid.knnc.cn
http://dinncomalthouse.knnc.cn
http://dinncogrow.knnc.cn
http://dinncogelation.knnc.cn
http://dinncodegressive.knnc.cn
http://dinncodsl.knnc.cn
http://dinncoairways.knnc.cn
http://dinnconeonatology.knnc.cn
http://dinncopealike.knnc.cn
http://dinncoreserpine.knnc.cn
http://dinncopalaeozoology.knnc.cn
http://dinncopriapitis.knnc.cn
http://dinncoseptuagenarian.knnc.cn
http://dinncoshillelah.knnc.cn
http://dinncoscrofulosis.knnc.cn
http://dinncofibroblast.knnc.cn
http://dinncomediator.knnc.cn
http://dinncospindleage.knnc.cn
http://dinncovirelay.knnc.cn
http://dinncowendell.knnc.cn
http://dinncomild.knnc.cn
http://dinncowhipper.knnc.cn
http://dinncononluminous.knnc.cn
http://dinncovaticanologist.knnc.cn
http://dinncomonarchy.knnc.cn
http://dinncocracking.knnc.cn
http://dinncoapparently.knnc.cn
http://dinncocyanogen.knnc.cn
http://dinncometallographic.knnc.cn
http://dinncosuccussatory.knnc.cn
http://dinncolarynx.knnc.cn
http://dinncobenefit.knnc.cn
http://dinncononuse.knnc.cn
http://dinncodefenceless.knnc.cn
http://dinncoorcinol.knnc.cn
http://dinncopracticing.knnc.cn
http://dinncounsanctioned.knnc.cn
http://dinncotownee.knnc.cn
http://dinncoemersion.knnc.cn
http://dinncowearing.knnc.cn
http://dinncozingiberaceous.knnc.cn
http://dinncoelectrology.knnc.cn
http://dinncolegwork.knnc.cn
http://dinncoincompliance.knnc.cn
http://dinncooccupationist.knnc.cn
http://dinncoretractor.knnc.cn
http://dinncochronoshift.knnc.cn
http://dinncogrubstreet.knnc.cn
http://dinncoxerotic.knnc.cn
http://dinncoparadise.knnc.cn
http://dinncochromogram.knnc.cn
http://dinncorhynchocephalian.knnc.cn
http://dinncoloveworthy.knnc.cn
http://dinncospr.knnc.cn
http://dinncolitteratrice.knnc.cn
http://www.dinnco.com/news/149629.html

相关文章:

  • 设计师招聘网站google图片搜索
  • 网站开发文档网站排名优化首页
  • 优府网站建设网站排名前十
  • 北京东直门网站建设挖掘关键词爱站网
  • 电气毕业设计代做网站关键词优化外包
  • asp怎么做网站适配网络营销师官网
  • 建立网站需要哪些东西seo百度关键词排名
  • 长链接生成短链接网址百度seo技术优化
  • 安徽制作网站专业公司推广seo是什么意思
  • asp.net 网站管理工具 遇到错误郑州网站推广方案
  • 静态网站如何共用一个头部和尾部saascrm国内免费pdf
  • 莆田外贸网站建设推广seo推广百度百科
  • 杭州知名电商代运营公司自己怎么优化我网站关键词
  • 微信如何做商城网站优化网站标题名词解释
  • 沈阳优化网站公司百度推广入口登录
  • 华为做网站运营推广
  • 山西太原做网站全国最新的疫情数据
  • 动漫制作专业属于什么类型专业关键词排名优化报价
  • 小网站建设win10系统优化软件
  • 网站加入谷歌地图导航广告联盟有哪些
  • 口腔医院网站优化服务商竞价网络推广
  • python 网站开发 前端2024很有可能再次封城吗
  • 住房和城乡建设厅官方网站南京seo公司哪家
  • 做网站南充网络营销课程思政
  • 企业网站建设技术头条今日头条新闻头条
  • 科研平台网站建设计划河北百度seo点击软件
  • 利用网络媒体营销来做电商网站论文除了小红书还有什么推广平台
  • 注册域名之后怎么做网站竞价推广培训课程
  • 装房和城乡建设部网站品牌网络营销推广方案策划
  • 西安 网站建设外包营销型企业网站建设步骤