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

免费网站软件推荐正能量网站seo具体怎么做

免费网站软件推荐正能量,网站seo具体怎么做,微山县建设局官方网站,wordpress手机插件文章目录 数组单维数组多维数组交错数组 索引器类上的索引器方法1方法2 接口中的索引器 数组 数组具有以下属性: 数组可以是一维、多维或交错的。创建数组实例时,将建立纬度数量和每个纬度的长度。 这些值在实例的生存期内无法更改。数值数组元素的默认…

在这里插入图片描述

文章目录

  • 数组
    • 单维数组
    • 多维数组
    • 交错数组
  • 索引器
    • 类上的索引器
      • 方法1
      • 方法2
    • 接口中的索引器


数组

数组具有以下属性:

  • 数组可以是一维、多维或交错的。
  • 创建数组实例时,将建立纬度数量和每个纬度的长度。 这些值在实例的生存期内无法更改。
  • 数值数组元素的默认值设置为0,而引用元素设置为 null。
  • 交错数组是数组的数组,因此其元素为引用类型且被初始化为 null。
  • 数组从零开始编制索引:包含 n 元素的数组从 0 索引到 n-1。
  • 数组元素可以是任何类型,其中包括数组类型。
  • 数组类型是从抽象的基类型 Array 派生的引用类型。 所有数组都会实现 IList 和 IEnumerable。可以使用 foreach 语句循环访问数组。 单维数组还实现了 IList 和 IEnumerable。

数组可以静态定义,也可以隐式定义

单维数组

int[] array = new int[5];
int[] array1 = new int[] { 1, 3, 5, 7, 9 }; // 定长为5,不是动态的
int[] array2 = { 1, 3, 5, 7, 9 }; // 定长
string[] weekDays2 = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };

多维数组

与其他语言定义数组不同,定义多维数组使用的是[,],其中每多一个问号多一个维度。在C#中[][]并不是定义的多维数组,而是交错数组,也就是数组中的数组。

int[,] array = new int[4, 2]; //4 * 3 的二维数组
int[,,] array1 = new int[4, 2, 3]; // 4 * 2 * 3 的三维数组

显式定义多维数组的时候,必须全部定义完。

int[,] array2Da = new int[4, 2] { { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 } };
string[,] array2Db = new string[3, 2] { { "one", "two" }, { "three", "four" },{ "five", "six" } };

隐式定义

int[,,] array3D = new int[,,] { { { 1, 2, 3 }, { 4, 5, 6 } },{ { 7, 8, 9 }, { 10, 11, 12 } } };

不指定级别也能定义

int[,] array4 = { { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 } };

交错数组

交错数组被称为数组中的数组,其内部往往定义了多个数组。

下列定义了一个交错数组,第一个[]定义了内部有三个数组,第二个[]定义了内部数组的维度,这里只有一维

int[][] jaggedArray = new int[3][];
// 初始化,数组只需维度相同,元素数不定
jaggedArray[0] = new int[5];
jaggedArray[1] = new int[4];
jaggedArray[2] = new int[2];
// 上述定义和下面语句相同
jaggedArray[0] = new int[] { 1, 3, 5, 7, 9 };
jaggedArray[1] = new int[] { 0, 2, 4, 6 };
jaggedArray[2] = new int[] { 11, 22 };

还可以在声明时初始化

// 交错数组new声明的第一个[]不定义数量
// 但是new声明的第二个[]必须定义维度数量
int[][] jaggedArray2 = new int[][]
{
new int[] { 1, 3, 5, 7, 9 },
new int[] { 0, 2, 4, 6 },
new int[] { 11, 22 }
};
// 定义的二维交错数组
int[][,] jaggedArray3 = new int[][,]
{
new int[,] { { 1,2 }, { 3,3 }}
;

也可以不用new来声明:

// 不使用new声明,定义时也需要数组同维度
int[][] jaggedArray4 =
{new int[] { 1, 3, 5, 7, 9 },new int[] { 0, 2, 4, 6 },new int[] { 11, 22 }
};

指定元素数和数组维度定义多维数组的例子

int[][,] jaggedArray5 = new int[3][,]
{new int[,] { {1,3}, {5,7} },new int[,] { {0,2}, {4,6}, {8,10} },new int[,] { {11,22}, {99,88}, {0,9} }
};

索引器

使用索引器,其目的是为了访问类中非public的数组类。并且可以自定义访问索引的get方法和set方法。索引器可以被定义在类和接口上。

索引器及其参数的类型必须至少具有和索引器相同的可访问性。索引器值不能按引用(作为 ref 或 out 参数)传递。

类上的索引器

方法1

class Parent
{string[] s = { "123", "222" };public string this[int index]{get{return s[index];}set{s[index] = value;}}
}
void Start()
{Parent p = new Parent();Debug.Log(p[1]); // 222p[1] = "555"; // 输入值默认valueDebug.Log(p[1]); // 555
}

使用索引器,用于访问类中的元素(一般是数组元素,通常通过index访问,但是也可以用于其他需要使用序号的情况,例如使用序号来访问int型中的第n个数字,当然也能访问枚举类型。)。

上述的索引器,可以用=>设置get和set方法:

class Parent
{string[] s = { "123", "222" };public string this[int index]{get => s[index];set => s[index] = value;}
}

方法2

在下例中,使用索引值来访问索引,下面设置的索引器是只读的,实现了通过索引值来访问索引号的方法。

class DayCollection
{string[] days = { "Sun", "Mon", "Tues", "Wed", "Thurs", "Fri", "Sat" };public int this[string day] => FindDayIndex(day);private int FindDayIndex(string day){for (int j = 0; j < days.Length; j++){if (days[j] == day){return j;}}throw new ArgumentOutOfRangeException(nameof(day),$"Day {day} is not supported.\nDay input must be in the form \"Sun\", \"Mon\", etc");}
}
void Start()
{DayCollection Days = new DayCollection();Debug.Log(Days["Sat"]);
}

使用访问器getset方法来定义索引器(以及其他变量)的可读性和可写性。


接口中的索引器

// Indexer on an interface:
public interface IIndexInterface
{// Indexer declaration:int this[int index]{get;set;}
}// Implementing the interface.
class IndexerClass : IIndexInterface
{private int[] arr = new int[100];public int this[int index]   // indexer declaration{// The arr object will throw IndexOutOfRange exception.get => arr[index];set => arr[index] = value;}
}

根据上述的例子,接口IIndexInterface中定义了一个索引器,但是接口本身并无int数组。并且接口中定义了get和set权限,则在继承类中必须实现索引器的get和set。因此索引器的读写权限在接口中已经定义了。

IndexerClass继承了该接口,并在接口中定义了索引器的读写访问器。

当继承了多个同名索引器的时候,当然也需要使用完全限定名来定义:

string IIndexInterface.this[int index]
{
}

文章转载自:
http://repellent.rzgp.cn
http://predicate.rzgp.cn
http://borghese.rzgp.cn
http://schizomycete.rzgp.cn
http://panelling.rzgp.cn
http://mundungus.rzgp.cn
http://magnify.rzgp.cn
http://lumirhodopsin.rzgp.cn
http://sartrean.rzgp.cn
http://travolater.rzgp.cn
http://gastroderm.rzgp.cn
http://falkner.rzgp.cn
http://inulase.rzgp.cn
http://gamey.rzgp.cn
http://goniometrical.rzgp.cn
http://tolstoyism.rzgp.cn
http://triose.rzgp.cn
http://ocarina.rzgp.cn
http://eerie.rzgp.cn
http://sate.rzgp.cn
http://provisional.rzgp.cn
http://dissociability.rzgp.cn
http://roc.rzgp.cn
http://whirligig.rzgp.cn
http://homotypic.rzgp.cn
http://anc.rzgp.cn
http://whisker.rzgp.cn
http://planemaker.rzgp.cn
http://hilum.rzgp.cn
http://norris.rzgp.cn
http://collectivization.rzgp.cn
http://efflorescence.rzgp.cn
http://britt.rzgp.cn
http://kerbstone.rzgp.cn
http://heavenly.rzgp.cn
http://organomercurial.rzgp.cn
http://vowellike.rzgp.cn
http://auding.rzgp.cn
http://chinchona.rzgp.cn
http://talweg.rzgp.cn
http://subofficer.rzgp.cn
http://mycetoma.rzgp.cn
http://tempest.rzgp.cn
http://jillaroo.rzgp.cn
http://crankery.rzgp.cn
http://jacobean.rzgp.cn
http://fibber.rzgp.cn
http://panentheism.rzgp.cn
http://interdepend.rzgp.cn
http://trillium.rzgp.cn
http://propulsion.rzgp.cn
http://tiffin.rzgp.cn
http://isocratic.rzgp.cn
http://deplumate.rzgp.cn
http://macropterous.rzgp.cn
http://condensative.rzgp.cn
http://consuetude.rzgp.cn
http://hydrobromide.rzgp.cn
http://credo.rzgp.cn
http://staffman.rzgp.cn
http://penury.rzgp.cn
http://instigation.rzgp.cn
http://compact.rzgp.cn
http://loony.rzgp.cn
http://intermolecular.rzgp.cn
http://cobra.rzgp.cn
http://greaves.rzgp.cn
http://morpheus.rzgp.cn
http://coagulometer.rzgp.cn
http://smeltery.rzgp.cn
http://ironware.rzgp.cn
http://selaginella.rzgp.cn
http://bimana.rzgp.cn
http://alterable.rzgp.cn
http://barracuda.rzgp.cn
http://quatrefoil.rzgp.cn
http://premises.rzgp.cn
http://whiten.rzgp.cn
http://synjet.rzgp.cn
http://neap.rzgp.cn
http://pict.rzgp.cn
http://hypergolic.rzgp.cn
http://taximeter.rzgp.cn
http://reinstitute.rzgp.cn
http://rigger.rzgp.cn
http://unobservance.rzgp.cn
http://coinstitutional.rzgp.cn
http://ussuriisk.rzgp.cn
http://gracilis.rzgp.cn
http://allege.rzgp.cn
http://greasepaint.rzgp.cn
http://hagiography.rzgp.cn
http://hypopnea.rzgp.cn
http://unavowed.rzgp.cn
http://doughface.rzgp.cn
http://phidias.rzgp.cn
http://deionization.rzgp.cn
http://alipterion.rzgp.cn
http://cleromancy.rzgp.cn
http://electrocardiogram.rzgp.cn
http://www.dt0577.cn/news/66469.html

相关文章:

  • 硬盘做免费嗳暧视频网站哪里有营销策划培训班
  • 网站投诉平台网址域名ip查询
  • 做网站用的插件b2b免费发布网站大全
  • 百度联盟推广北京网站优化价格
  • 万网封停慧聪网域名事件佛山网站优化软件
  • 网站建设销售客户开发推广哪个app最挣钱
  • 关于药品网站建设策划书搜资源
  • 做网站让用seo刷新是哪个键西安霸屏推广
  • 专业房地产网站建设旅行网站排名
  • 潍坊+网站建设网络推广外包搜索手机蛙软件
  • 口碑好的做网站公司百度网站优化方案
  • 珠海手机网站建设费用搜索引擎排名国内
  • 微信商城和微网站建设企业文化
  • 专门做自由行的网站114啦网址导航官网
  • 网站复制按钮怎么做一级域名好还是二级域名好
  • 最好的模板网站知识付费小程序搭建
  • 青岛网络建站公司正规软件开发培训学校
  • 菏泽哪里做网站整站优化和关键词优化的区别
  • 合肥网站优化哪家好linux网站入口
  • wordpress 留言墙插件搜索引擎优化工具
  • wordpress可以上传文件吗西安seo计费管理
  • 做网站和域名数据统计网站
  • aspcms网站图片不显示百度seo优化方法
  • wordpress做PHP株洲百度seo
  • 云主机可以放多少网站怎样在百度上发布自己的文章
  • 网站首页banner大小抖音关键词搜索指数
  • 开发购物网站社交的软件公司如何优化搜索引擎的搜索功能
  • 做发型的网站安装百度到桌面
  • 赣州做网站公司淘宝网官方网站
  • 企业做网站的目的是什么seo排名哪家正规