텍스트 파일의 모든 입력 값을 저장할 수있는 목록을 만들었습니다. 이제 다른 수업에서이 목록에 액세스해야합니다. 코드가 변경해야합니까?다른 클래스의 목록에 액세스하는 방법
public static void boxdetails()
{
String line;
List<Box> listofboxes = new List<Box>();
try
{
using (StreamReader sr = new StreamReader("c:/boxvalues.txt"))
while ((line = sr.ReadLine()) != null)
{
// create new instance of container for each line in file
Box box = new Box();
// List<Box> listofboxes = new List<Box>();
string[] Parts = line.Split(' ');
// set non-static properties of container
box.bno = Parts[0];
box.length = Convert.ToDouble(Parts[1]);
box.height = Convert.ToDouble(Parts[2]);
box.depth = Convert.ToDouble(Parts[3]);
box.volume = Convert.ToDouble(Parts[4]);
box.placed = Convert.ToBoolean(Parts[5]);
// add container to list of containers
}
listofboxes.Add(box);
Console.WriteLine((box.bno) + "is ADDED");
listofboxes = listofboxes.OrderBy(x => x.volume).ToList();
}
//[code incomplete]