新手~~关于System.Collections.ArrayList类的.Item 属性疑惑~~~

zpzpzp39941192 2005-03-11 03:47:35
关于System.Collections.ArrayList类的.Item 属性疑惑~~~

看帖子说,arraylist类定义的动态数组可以用.add()方法动态添加,然后用.item()读取.可我咋没找到item呢~~请指教~~
在msdn上找了个ArrayList例子里的,arraylist实例也不灵.迷茫~~
例子是

using System;
using System.Collections;
public class SamplesArrayList {

public static void Main() {

// Creates and initializes a new ArrayList.
ArrayList myAL = new ArrayList();
myAL.Add("Hello");
myAL.Add("World");
myAL.Add("!");

// Displays the properties and values of the ArrayList.
Console.WriteLine( "myAL" );
Console.WriteLine( "\tCount: {0}", myAL.Count );
Console.WriteLine( "\tCapacity: {0}", myAL.Capacity );
Console.Write( "\tValues:" );
PrintValues( myAL );
}

public static void PrintValues( IEnumerable myList ) {
System.Collections.IEnumerator myEnumerator = myList.GetEnumerator();
while ( myEnumerator.MoveNext() )
Console.Write( "\t{0}", myEnumerator.Current );
Console.WriteLine();
}
}
/*
This code produces the following output.

myAL
Count: 3
Capacity: 16
Values: Hello World !
*/
...全文
155 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
supergoalcn 2005-03-12
  • 打赏
  • 举报
回复
item是索引器,你应该用myAL[0]来得到之前存入的对象。
由于Collections都实现了IEnumerator接口,所以可以将一个Collections对象或其子类的对象转换成IEnumerator接口,然后就可以对其成员进行逐一列举了。
zpzpzp39941192 2005-03-12
  • 打赏
  • 举报
回复
谢谢二位.
Ivony()
WTaoboy(SnowMans)
WTaoboy 2005-03-11
  • 打赏
  • 举报
回复
this. myAL[1].ToString();
Ivony 2005-03-11
  • 打赏
  • 举报
回复
在C#里面是索引器,直接用[]来取。myAL[0]
zpzpzp39941192 2005-03-11
  • 打赏
  • 举报
回复
http://dev.csdn.net/article/64/64218.shtm

这个上说的

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧