728x90

인터페이스로부터 직접 new를 사용하여 객체를 생성할 수 없다.

public interface IComparable
{
   // 멤버 앞에 접근제한자 사용 안함
   int CompareTo(object obj);
}
public class MyClass : IComparable , IDbConnection
{
   private int key;
   private int value;

   // IComparable 의 CompareTo 메서드 구현
   public int CompareTo(object obj)
   {
      MyClass target = (MyClass)obj;
      return this.key.CompareTo(target.key);
   }
}

 

728x90

+ Recent posts