Реализация event в программе - C#
Формулировка задачи:
Есть код. Помогите пожалуйста реализовать event
using System;
class TextField
{
protected string __text;
public delegate void TextFieldCoordsChangedHandler(TextField sender, )
public TextField()
{
__text = "";
}
public TextField(string some)
{
__text = some;
}
public int length()
{
return __text.Length;
}
public string text()
{
return __text;
}
public static TextField read()
{
TextField tf = new TextField();
while (true)
{
ConsoleKeyInfo cki = Console.ReadKey(true);
if (cki.Key == ConsoleKey.Enter)
{
Console.Write("\n");
break;
}
tf.__text += cki.KeyChar;
Console.Write(cki.KeyChar);
}
return tf;
}
}
class PasswordField : TextField
{
public static PasswordField read()
{
PasswordField tf = new PasswordField();
while (true)
{
ConsoleKeyInfo cki = Console.ReadKey(true);
if (cki.Key == ConsoleKey.Enter)
{
Console.Write("\n");
break;
}
tf.__text += cki.KeyChar;
Console.Write("*");
}
return tf;
}
}
class program
{
public static void Main(string[] args)
{
Console.Write("Login: ");
TextField login = TextField.read();
Console.Write("Password: ");
PasswordField password = PasswordField.read();
if (login.text() == "admin" && password.text() == "admin")
Console.WriteLine("Hello, admin");
else
Console.WriteLine("Hello, hacker");
Console.ReadKey();
}
}Решение задачи: «Реализация event в программе»
textual
Листинг программы
if(OnTextChanged != null) OnTextChanged(text)