//测试ArrayList的用法
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace Struct
{
class Student
{
ArrayList maths;
ArrayList physics;
ArrayList enghish;
ArrayList chinese; public void Maths() //向maths中添加正数
{
maths = new ArrayList();
int score= Convert.ToInt32(Console.ReadLine().ToString().Trim());
if (score != 101)
{
maths.Add(score);
Maths();
}
else
{
return;
}
} public void Physics() //向physics中添加正数
{
physics = new ArrayList();
int score = Convert.ToInt32(Console.ReadLine().ToString().Trim());
if(score!=101)
{
physics.Add(score);
Physics();
}
else
{
return;
}
} public void Enghish() //向enghish中添加正数
{
enghish = new ArrayList();
int score = Convert.ToInt32(Console.ReadLine().ToString().Trim());
if (score != 101)
{
enghish.Add(score);
Enghish();
}
else
{
return;
}
}
public void Chinese() //向chinese中添加正数
{
chinese = new ArrayList();
int score = Convert.ToInt32(Console.ReadLine().ToString().Trim());
if (score != 101)
{
chinese.Add(score);
Chinese();
}
else
{
return;
}
}
public static void Main()
{ Student s = new Student();
s.Maths();
s.Physics();
s.Enghish();
s.Chinese(); foreach( object item in s.maths) //输出maths中的值
{
Console.Write(item.ToString());
}
foreach (object item in s.physics) //输出physics中的值
{
Console.Write(item.ToString());
}
Console.WriteLine(); foreach (object item in s.enghish) //输出enghist中的值
{
Console.Write(item.ToString());
}
foreach (object item in s.chinese) //输出chinese中的值
{
Console.Write(item.ToString());
}
Console.Read();
}
}
}
/***
foreach( object item in s.maths) //输出maths中的值
{
Console.Write(item.ToString());
}
foreach (object item in s.physics) //输出physics中的值
{
Console.Write(item.ToString());
}
Console.WriteLine(); foreach (object item in s.enghish) //输出enghist中的值
{
Console.Write(item.ToString());
}
foreach (object item in s.chinese) //输出chinese中的值
{
Console.Write(item.ToString());
}****/这四个foreach中的Console.Write(item.ToString());为什么在命令行中不输出。四个ArrayList对象我已在命令行中输入了整数。
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace Struct
{
class Student
{
ArrayList maths;
ArrayList physics;
ArrayList enghish;
ArrayList chinese; public void Maths() //向maths中添加正数
{
maths = new ArrayList();
int score= Convert.ToInt32(Console.ReadLine().ToString().Trim());
if (score != 101)
{
maths.Add(score);
Maths();
}
else
{
return;
}
} public void Physics() //向physics中添加正数
{
physics = new ArrayList();
int score = Convert.ToInt32(Console.ReadLine().ToString().Trim());
if(score!=101)
{
physics.Add(score);
Physics();
}
else
{
return;
}
} public void Enghish() //向enghish中添加正数
{
enghish = new ArrayList();
int score = Convert.ToInt32(Console.ReadLine().ToString().Trim());
if (score != 101)
{
enghish.Add(score);
Enghish();
}
else
{
return;
}
}
public void Chinese() //向chinese中添加正数
{
chinese = new ArrayList();
int score = Convert.ToInt32(Console.ReadLine().ToString().Trim());
if (score != 101)
{
chinese.Add(score);
Chinese();
}
else
{
return;
}
}
public static void Main()
{ Student s = new Student();
s.Maths();
s.Physics();
s.Enghish();
s.Chinese(); foreach( object item in s.maths) //输出maths中的值
{
Console.Write(item.ToString());
}
foreach (object item in s.physics) //输出physics中的值
{
Console.Write(item.ToString());
}
Console.WriteLine(); foreach (object item in s.enghish) //输出enghist中的值
{
Console.Write(item.ToString());
}
foreach (object item in s.chinese) //输出chinese中的值
{
Console.Write(item.ToString());
}
Console.Read();
}
}
}
/***
foreach( object item in s.maths) //输出maths中的值
{
Console.Write(item.ToString());
}
foreach (object item in s.physics) //输出physics中的值
{
Console.Write(item.ToString());
}
Console.WriteLine(); foreach (object item in s.enghish) //输出enghist中的值
{
Console.Write(item.ToString());
}
foreach (object item in s.chinese) //输出chinese中的值
{
Console.Write(item.ToString());
}****/这四个foreach中的Console.Write(item.ToString());为什么在命令行中不输出。四个ArrayList对象我已在命令行中输入了整数。
public void Maths() //向maths中添加正数
每次都亲空了
*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) http://feiyun0112.cnblogs.com/
public Student()
{
maths = new ArrayList();
Maths();
}