Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the common properties and methods of C # array

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

本篇内容主要讲解"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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report