// 델리게이트 선언과 비슷하다
// ;로 정의만 한다
// 인터페이스의 정의된 구현을 반드시 제공한다
interface ISampleInterface
{
void SampleMethod();
}
// 상속은 하나만 받을수 있다
// 부모 <- 부모 <- 자식 받을수 있다
class ImplementationClass : ISampleInterface // , 인터페이스, 인터페이스 가능
{
// Explicit interface member implementation:
void ISampleInterface.SampleMethod()
{
// Method implementation.
}
static void Main()
{
// Declare an interface instance.
ISampleInterface obj = new ImplementationClass();
// Call the member.
obj.SampleMethod();
}
}
using System;
// Define a custom delegate that has a string parameter and returns void.
delegate void CustomCallback(string s);
class TestClass
{
// Define two methods that have the same signature as CustomCallback.
static void Hello(string s)
{
Console.WriteLine($" Hello, {s}!");
}
static void Goodbye(string s)
{
Console.WriteLine($" Goodbye, {s}!");
}
static void Main()
{
// Declare instances of the custom delegate.
CustomCallback hiDel, byeDel, multiDel, multiMinusHiDel;
//대리자변수 선언 4개
// In this example, you can omit the custom delegate if you
// want to and use Action<string> instead.
//Action<string> hiDel, byeDel, multiDel, multiMinusHiDel;
// Initialize the delegate object hiDel that references the
// method Hello.
hiDel = Hello;
// Initialize the delegate object byeDel that references the
// method Goodbye.
byeDel = Goodbye;
// The two delegates, hiDel and byeDel, are combined to
// form multiDel.
// 대리자변수 + 대리자변수 결합
multiDel = hiDel + byeDel;
// Remove hiDel from the multicast delegate, leaving byeDel,
// which calls only the method Goodbye.
multiMinusHiDel = multiDel - hiDel;
Console.WriteLine("Invoking delegate hiDel:");
hiDel("A");
Console.WriteLine("Invoking delegate byeDel:");
byeDel("B");
Console.WriteLine("Invoking delegate multiDel:");
multiDel("C");
Console.WriteLine("Invoking delegate multiMinusHiDel:");
multiMinusHiDel("D");
}
}
/* Output:
Invoking delegate hiDel:
Hello, A!
Invoking delegate byeDel:
Goodbye, B!
Invoking delegate multiDel:
Hello, C!
Goodbye, C!
Invoking delegate multiMinusHiDel:
Goodbye, D!
*/
// abstract = 추상클래스
'게임 플랫폼 응용 프로그래밍' 카테고리의 다른 글
Vecter3 수업내용20240924 (0) | 2024.09.24 |
---|---|
수업내용 (0) | 2024.09.23 |