유니티
[C#] Interface
simstealer
2022. 7. 20. 15:34
Interface는 메세지를 정의하기 위해서 사용한다.
Interface는 메서드만 담을 수 있다.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
// 인터페이스 만드는 법
public interface IFlyable
{
void Fly();
}
public interface IEatable
{
void Eat();
}
// 인터페이스의 내용을 구현 하지 않으면 빨간줄이 생성된다.
public class Bird : IFlyable, IEatable
{
public void Eat()
{
// 먹는다
}
public void Fly()
{
// 난다
}
}
// C#에서 클래스는 다중 상속을 금지한다.
// 인터페이스는 예외.