All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
构建安全的Xml,Web,Service系列(一)_[Asp.Net教程]
ASP.NET开发经验(3):使用,GUID,值来作为数据库行标识_[Asp.Net教程]
PHP的十个高级技巧(中)_[PHP教程]
用shtml来include网页文件(须开启SSI)_[Html教程]
WebService服务和ajax使用教程_.net资料_编程技术
C#,3.0新特性初步研究,Part1:使用隐含类型的本地变量_[Asp.Net教程]
PEAR--HTML_QuickForm与Smarty,的结合应用_php资料_编程技术
asp.net2.0验证控件之RequiredFieldValidator控件使用方法
MySQL与ASP.NET配合更强大_.net资料_编程技术
DropDownList联动简单实例_[Asp.Net教程]
Reading number is top 10 pictures
The little girl with long hair1
福利是必须的
Magnificent cloud1
Japanese snow monkeys in the hot spring to keep warm, close their eyes to enjoy
到南昌西站了3
初吻给了谁?
漂亮脸蛋魔鬼身材1
Perfect small Laurie1
29 the belle stars after bath figure3
Extremely rare TianShan Mountains snow lotus2
Download software ranking
Eclipse 4.2.2 For Win64
变速齿轮3.26
C#COM编程指南
Rio big adventure
Ashlynn Video2
致我们终将逝去的青春
尖东毒玫瑰A
Twenty piece of palm leaf
Boxer's Top ten classic battle8
好色的外科大夫
qq published in(发表于) 2014/7/11 9:19:37 Edit(编辑)
C#中常用的集合类型

C#中常用的集合类型

C#中常用的集合类型

C#中常用的集合类型

1.ArrayList类

ArrayList类主要用于对一个数组中的元素进行各种处理。在ArrayList中主要使用Add、Remove、RemoveAt、Insert 4个方法对栈进行操作。Add方法用于将对象添加到 ArrayList 的结尾处,Remove方法用于从 ArrayList 中移除特定对象的第一个匹配项,RemoveAt方法用于移除 ArrayList 的指定索引处的元素,Insert方法用于将元素插入ArrayList的指定索引处。

* 示例

ArrayList的使用

示例将介绍如何创建一个ArrayList、如何添加项、如何移除项以及如何遍历ArrayList。程序代码如下:

using System.Collections;//引入命名空间

namespace _4

{

class ArrayListTest

{

static void Main(string[] args)

{

ArrayList arrlist = new ArrayList();//实例化一个ArrayList对象

//使用Add方法向ArrayList中添加元素,将元素添加到ArrayList对象的末尾

//本教程来自网站源代码http://www.isstudy.com

arrlist.Add("苹果");

arrlist.Add("香蕉");

arrlist.Add("葡萄");

foreach (int n in new int[3] { 0, 1, 2 })

{

arrlist.Add(n);

}

//移除值为0的第一个元素

arrlist.Remove(0);

//移除当前索引为3的元素,即第4个元素

arrlist.RemoveAt(3);

//在指定索引处添加一个元素

arrlist.Insert(1, "apple");

//遍历ArrayList,并输出所有元素

for (int i = 0; i < arrlist.Count; i++)

{

Console.WriteLine(arrlist[i].ToString());

}

}

}

}

键运行程序,运行结果如图1所示。



图1 ArrayList示例运行结果图

完整程序代码如下:

★★★★★主程序文件完整程序代码★★★★★:

using System;

using System.Collections.Generic;

using System.Text;

using System.Collections;

namespace _4

{

class ArrayListTest

{

static void Main(string[] args)

{

ArrayList arrlist = new ArrayList();//实例化一个ArrayList对象

//使用Add方法向ArrayList中添加元素,将元素添加到ArrayList对象的末尾

//本教程来自网站源代码
http://www.isstudy.com

arrlist.Add("苹果");

arrlist.Add("香蕉");

arrlist.Add("葡萄");

foreach (int n in new int[3] { 0, 1, 2 })

{

arrlist.Add(n);

}

//移除值为0的第一个元素

arrlist.Remove(0);

//移除当前索引为3的元素,即第4个元素

arrlist.RemoveAt(3);

//在指定索引处添加一个元素

arrlist.Insert(1, "apple");

//遍历ArrayList,并输出所有元素

for (int i = 0; i < arrlist.Count; i++)

{

Console.WriteLine(arrlist[i].ToString());

}

}

}

}



添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.