안녕하세요. 저는 회사의 Pickups 또는 Delivery를 내 교과목 목록에 추가 할 수있는 프로그램을 디자인해야합니다. 아래 목록과 같이 방문이라는 목록을 만들었습니다.하나의 목록 만 사용하는 방법
각 픽업이나 배송을 목록에 추가하여 원래 픽업을 구분할 수있는 방법을 알고 싶습니다. 픽업 또는 배송 만 표시 할 수 있습니다.
class List
{
/*
* This object represents the List. It has a 1:M relationship with the Visit class
*/
private List<Visits> visits = new List<Visits>();
//List object use to implement the relationshio with Visits
public void addVisits(Visits vis)
{
//Add a new Visit to the List
visits.Add(vis);
}
public List<String> listVisits()
{//Generate a list of String objects, each one of which represents a Visit in List.
List<String> listVisits = new List<string>();
//This list object will be populated with Strings representing the Visits in the lists
foreach (Visits vis in visits)
{
String visAsString = vis.ToString();
//Get a string representing the current visit object
listVisits.Add(visAsString);
//Add the visit object to the List
}
return listVisits;
//Return the list of strings
}
public Visits getVisits(int index)
{
//Return the visit object at the <index> place in the list
int count = 0;
foreach (Visits vis in visits)
{
//Go through all the visit objects
if (index == count)
//If we're at the correct point in the list...
return vis;
//exit this method and return the current visit
count++;
//Keep counting
}
return null;
//Return null if an index was entered that could not be found
}
는 SHOW 코드
/*
* Update the list on this form the reflect the visits in the list
*/
lstVisits.Items.Clear();
//Clear all the existing visits from the list
List<String> listOfVis = theList.listVisits();
//Get a list of strings to display in the list box
lstVisits.Items.AddRange(listOfVis.ToArray());
//Add the strings to the listBox. Note to add a list of strings in one go we have to
//use AddRange and we have to use the ToArray() method of the list that we are adding
일반적으로 두 개의 목록이 있습니다. 하나는 픽업을위한 것이고 다른 하나는 배달을위한 것입니다. 방문 유형을 구별 할 필요가 없을 때 (즉 방문 클래스에서 물건을 만지는 경우, 즉 메소드가 각 구체 유형에서 다른 (다형성) 구현을 가지고 있더라도 하나의 "방문"목록을 갖는 것이 맞습니다.). – Cameron
좋아 그럼 그 경우에는 배달을위한 버튼 하나와 요약을 보여주기 위해 listBox에 추가하는 픽업을위한 버튼 하나가 있습니다 ... 어떻게 픽업 전용 버튼이 있는지 또는 배송에만 맞는지 버튼을 구현할 수 있습니까 – TAM