求一道C#编程题
编程题:1、请完成登陆验证:
1)、如果输入的用户名是ASP, 密码是ASP,则登录成功并触发登录成功事件,输出“登录成功”;
2)、反之,则触发登录失败事件,输出“用户名或密码错误”;
EventReceiver.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleLoginTest
{
class EventReceiver
{
public void Success()
{
Console.WriteLine("登录成功");
}
public void Failed()
{
Console.WriteLine("登录失败");
}
}
}
Login.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleLoginTest
{
public delegate void LoginEventHandler();
class Login
{
public event LoginEventHandler loginSucceed;
public event LoginEventHandler loginFailed;
public void DoCheck(string userName, string password)
{
if (userName == "asp" && password == "asp")
{
if (loginSucceed != null)
{
loginSucceed();
}
}
else
{
if (loginFailed != null)
{
loginFailed();
}
}
}
}
}
Program
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleLoginTest
{
class Program
{
static void Main(string[] args)
{
string userName = string.Empty;
string password = string.Empty;
Login login = new Login();
EventReceiver er = new EventReceiver();
login.loginSucceed += new LoginEventHandler(er.Success);
login.loginFailed += new LoginEventHandler(er.Failed);
Console.WriteLine("请输入用户名");
userName = Console.ReadLine();
Console.WriteLine("请输入密码");
password = Console.ReadLine();
login.DoCheck(userName, password);
Console.ReadKey();
}
}
}
这是几个cs文件,上面那个程序时我要写的,麻烦高人再整合一下