티스토리 뷰

C#/복습

인터페이스,구조체,상속 복습

Game Client Lee Hwanguk 2023. 2. 24. 01:27

#인터페이스

https://learn.microsoft.com/ko-kr/dotnet/csharp/programming-guide/interfaces/explicit-interface-implementation

 

명시적 인터페이스 구현 - C# 프로그래밍 가이드

클래스는 C#에서 동일한 시그니처를 가진 멤버를 포함하는 인터페이스를 구현할 수 있습니다. 명시적 구현에서는 하나의 인터페이스에 고유한 클래스 멤버를 만듭니다.

learn.microsoft.com

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace inter
{
    //interface 연습
    //다중 상속이 가능
    //필드를 포함하지 않음, 모든 맴버는 기본 public으로 지정되어있음
    //추상적인 맴버를 갖음
    interface IMyInterfaceA //public
    {
        void Open(); //추상적 맴버
    }
    interface IMyInterfaceB
    {
        void Open(); 
    }

    class MyClass:IMyInterfaceA, IMyInterfaceB
    {
        static void Main(string[] args)
        {
            MyClass myClass=new MyClass();

            IMyInterfaceA imca = myClass;
            imca.Open();

            IMyInterfaceB imcb= myClass;
            imcb.Open();
        }

        void IMyInterfaceA.Open()
        {
            Console.WriteLine("IMyInterfaceA.Open");
        }
        void IMyInterfaceB.Open() 
        {
            Console.WriteLine("IMyInterfaceB.Open");

        }
    }
}

#인터페이스
*인터페이스(다중 상속O)
*필드 포함 X, 모든 맴버는 public으로 기본 지정
*추상적인 맴버를 갖음

'C# > 복습' 카테고리의 다른 글

Unity복습(Skill,Enemy hpPoint)  (0) 2023.02.20
Unity 복습 (Button, Switch,Slide,Popup)  (0) 2023.02.19
자료구조-그래프  (0) 2023.01.29
직렬화, 역직렬화  (0) 2023.01.24
Linq  (0) 2023.01.23
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
글 보관함