Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the common properties and methods of C # array

Shulou Source: shulou.com Published: 2022-06-02 09:16:07 10月28日 Update

本篇内容主要讲解"C#数组常用属性和方法有哪些",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"C#数组常用属性和方法有哪些"吧!

C#数组实际上是对象。System.Array 是所有数组类型的抽象基类型。提供创建、操作、搜索和排序数组的方法,因而在公共语言运行库中用作所有数组的基类。因此所有C#数组都可以使用它的属性和方法。

下面介绍一些常用属性和方法:

◆Length属性:表示数组所有维数中元素的总数。

如:

int [] number={1,2,3,4}; number.Length的值为4;

◆Rank属性:表示数组中的维数。

如:

string[,] names = new string[5,4];

names.Rank的值为2。

◆Sort方法:对一维数组排序。它是Array类的静态方法.

如:

string [] name=new string[]{"xi","ang","zhang","chun"}; Array.Sort(name); foreach(string s in name) { Console.WriteLine(s); }

◆Reverse方法:反转一维数组

如

Array.Reverse(name);

◆GetLowerBound与GetUpperBound方法:数组指定维度的下限与上限

如:

int [,,] number=new int[4,3,2]{{{1,2},{2,3},{3,4}},{{4,5},{5,6},

{6,7}},{{7,8},{8,9},{9,10}},{{10,11},{11,12},{12,13}}};

for(int i=number.GetLowerBound(0);i

Tags: Arrays methods attributes attributes commonly used elements content actual type one-dimensional learning sorting practical deeper upper limit lower limit medium use interest practicality actually Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Microsoft MySQL OPPO Reno Shulou Technology