C# / .NET 알고리즘과 퀴즈
본 알고리즘 퀴즈 문제는 C#/.NET 개발자를 위한 알고리즘 인터뷰 혹은 C# 프로그래밍을 통한
문제 해결 알고리즘을 연구해 보는데 도움이 되고자 작성되었습니다.
문제 해결 알고리즘을 연구해 보는데 도움이 되고자 작성되었습니다.
퀴즈 질문 | |
예상답변/설명 | 속성(Property), 메서드(Method), 이벤트(Event)를 각각 1개씩 갖는 IAction 인터페이스를 아래와 같이 작성할 수 있다.
public interface IAction
{
string ActionName { get; set; }
void Action(int id);
event EventHandler ActionComplete;
}
[추가질문] 위의 인터페이스를 구현하는 클래스 MyAction을 쓰시오. Action()메서드가 끌나지 전에 ActionComplete 이벤트를 Fire하시오. [A] 아래는 IAction을 구현한 한 클래스 예제이다.
public class MyAction : IAction
{
public string ActionName
{
get;
set;
}
public void Action(int id)
{
DoAction(id);
if (ActionComplete != null)
{
ActionComplete(this, EventArgs.Empty);
}
}
private void DoAction(int id)
{
//.... 생략 ....
}
public event EventHandler ActionComplete;
}
|