主题:如何取出ArrayList中的值?
如何才能把ArrayList中的值取出,请高手赐教.
using System;
using System.Collections;
class TestArraylist
{
public static void Main()
{
ArrayList list = new ArrayList(1);
list.Add(new Person("TOM",100,20));
list.Add(new Person("Alice", 30, 50));
list.Add(new Person("JACK",20,20));
Person Bob = new Person("Bob", 101, 10);
for (int i = 0; i < list.Count; i++)
{
// 如何取出ARRAYLIST 中的值
Console.WriteLine("Element {0} is \"{1}\"", i,list[i]);
}
Console.ReadLine();
}
public class Person
{
public string name;
public int age;
public int score;
public Person(string s, int i,int j)
{
name = s;
age = i;
score = j;
}
}
}
using System;
using System.Collections;
class TestArraylist
{
public static void Main()
{
ArrayList list = new ArrayList(1);
list.Add(new Person("TOM",100,20));
list.Add(new Person("Alice", 30, 50));
list.Add(new Person("JACK",20,20));
Person Bob = new Person("Bob", 101, 10);
for (int i = 0; i < list.Count; i++)
{
// 如何取出ARRAYLIST 中的值
Console.WriteLine("Element {0} is \"{1}\"", i,list[i]);
}
Console.ReadLine();
}
public class Person
{
public string name;
public int age;
public int score;
public Person(string s, int i,int j)
{
name = s;
age = i;
score = j;
}
}
}