0
저는 C#에서 이벤트를 사용하는 방법을 배우고 있으므로 매우 간단한 연습 예제가 있어야합니다. 데이터베이스에서 List로 읽는 객체가 있습니다. 데이터베이스의 항목이 삭제되면 이벤트가 트리거됩니다. DBWrapper 객체가 다른 클래스에 의해 트리거 된 이벤트를 수신하도록하려면 어떻게해야합니까?개체 간 C# 이벤트 처리기
public class DBWrapper
{
private List<DBStruct> _List;
public List<DBStruct> GetList
{
get
{
return _List;
}
}
void OnDeleted(object sender, EventArgs e)
{
//Re-read the list from db. I could probably do
//something with Lazy<T> loading to eliminate the event stuff
//but that's not the point.
_List = (from d in db select d).ToList();
}
}
그때 이벤트 트리거하는 삭제() 메소드를 다른 클래스가
: 어떻게
void Test()
{
DBWrapper dbw = new DBWrapper();
Console.WriteLine(dbw.GetList);
//Apple=1,Banana=2,Cake=3
DeleteDB ddb = new DeleteDB();
ddb.Delete(1);
Console.WriteLine(dbw.GetList);
//Banana=2,Cake=3
}
:
public class DeleteDB
{
public void Delete(int index)
{
//delete from db where d.ID = index
//fire deletion event to a DBWrapper object
}
}
이 내 출력이 원하는 것을 본질적를 하나의 객체가 다른 객체에 의해 트리거 된 이벤트를 수신합니까?
'd in db select d'에서 '점을 기입하는 것'이 없습니다. 그냥'db'라고 써라. – SLaks