using System.Xml;
namespace CSharp1
{
//Observer Pattern
internal class Program
{
static void OnInputTest()
{
Console.WriteLine();
Console.WriteLine("Input Received!");
}
static void Main(string[] args)
{
InputManager inputManager = new InputManager();
inputManager.InputKey += OnInputTest;
while (true)
{
inputManager.Update();
}
}
}
}
using System;
namespace CSharp1
{
class InputManager
{
public delegate void OnInputKey();
public event OnInputKey InputKey;
public void Update()
{
if (Console.KeyAvailable == false) return;
ConsoleKeyInfo info = Console.ReadKey();
if (info.Key == ConsoleKey.A)
{
InputKey();
}
}
}
}
'C#' 카테고리의 다른 글
Exception(예외 처리) (0) | 2023.07.12 |
---|---|
Lambda(람다식) (0) | 2023.07.12 |
Delegate(대리자) (0) | 2023.07.10 |
Property(프로퍼티) (0) | 2023.07.10 |
Interface (0) | 2023.07.10 |