请问,如何得到ArrayList中的某一个元素的值?

supere 2003-10-17 08:47:37
请问,如何得到ArrayList中的某一个元素的值?
...全文
1170 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
poetc 2003-10-17
  • 打赏
  • 举报
回复
跟数组一样用呀。
runsoft 2003-10-17
  • 打赏
  • 举报
回复
接分,经管我不懂。呵呵。
gaisylly 2003-10-17
  • 打赏
  • 举报
回复
这是foreach的
using System;
using System.Collections;

namespace ConsoleApplication1
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: 在此处添加代码以启动应用程序
//
ArrayList arraylist = new ArrayList();
arraylist.Add("Hello");
arraylist.Add("World");
arraylist.Add("!");
foreach (string s in arraylist)
{
Console.Write( "{0}\n", s );
}
}
}
}
haoliqi 2003-10-17
  • 打赏
  • 举报
回复
up
gaisylly 2003-10-17
  • 打赏
  • 举报
回复
再或者
using System;
using System.Collections;

namespace ConsoleApplication1
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: 在此处添加代码以启动应用程序
//
ArrayList arraylist = new ArrayList();
arraylist.Add("Hello");
arraylist.Add("World");
arraylist.Add("!");

for (int i=0;i<arraylist.Count;++i)
{
Console.Write( "{0}\n", arraylist[i] );
}
}
}
}
gaisylly 2003-10-17
  • 打赏
  • 举报
回复
或者
using System;
using System.Collections;

namespace ConsoleApplication1
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: 在此处添加代码以启动应用程序
//
ArrayList arraylist = new ArrayList();
arraylist.Add("Hello");
arraylist.Add("World");
arraylist.Add("!");

System.Collections.IEnumerator Enumerator = arraylist.GetEnumerator();
while (Enumerator.MoveNext())
{
Console.Write( "{0}\n", Enumerator.Current );
}
}
}
}
rgbcn 2003-10-17
  • 打赏
  • 举报
回复
接分
Stevetan81 2003-10-17
  • 打赏
  • 举报
回复
xxx[int i]
or xxx["memberName"]
gaisylly 2003-10-17
  • 打赏
  • 举报
回复
FOR EACH IN
cqnimin 2003-10-17
  • 打赏
  • 举报
回复
呵呵,接分:)
kuangsha007 2003-10-17
  • 打赏
  • 举报
回复
^_^ ing,既然解决了就好。
shajie 2003-10-17
  • 打赏
  • 举报
回复
既然已经解决了,就接分吧,:)
antshome 2003-10-17
  • 打赏
  • 举报
回复
XXX[0]

可能还需要强制类型转换一下
topsonstar 2003-10-17
  • 打赏
  • 举报
回复
用索引
supere 2003-10-17
  • 打赏
  • 举报
回复
ArrayList没有这个方法吧
allen1981813 2003-10-17
  • 打赏
  • 举报
回复
SetValue方法
supere 2003-10-17
  • 打赏
  • 举报
回复
晕!已经解决!送分给第一个回答的人吧

110,532

社区成员

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

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

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