理解 事件委托后 直接写的简单代码··
using
System;
/// <summary>
/// 事件 委托 简单应用
/// </summary>
public class key:EventArgs
{
private string _name;
public key( string name)
{
this ._name = name;
}
public string Name
{
get { return _name; }
}
}
public class test
{
public delegate void getKey( object sender, key e);
public event getKey printChar;
public string EEEE = " test " ;
public void run( )
{
bool finish = false ;
do
{
string name = Console.ReadLine();
if (name != "" )
{
printChar( this , new key(name));
}
} while ( ! finish);
}
}
public class mm
{
public static void Main()
{
test a = new test();
a.printChar += new test.getKey(Consoles);
a.run( );
}
public static void Consoles( object sender,key e)
{
Console.WriteLine( " 输入,,,{0},{1},{2} " ,e.Name,((test)sender).EEEE,e.ToString());
}
}
/// <summary>
/// 事件 委托 简单应用
/// </summary>
public class key:EventArgs
{
private string _name;
public key( string name)
{
this ._name = name;
}
public string Name
{
get { return _name; }
}
}
public class test
{
public delegate void getKey( object sender, key e);
public event getKey printChar;
public string EEEE = " test " ;
public void run( )
{
bool finish = false ;
do
{
string name = Console.ReadLine();
if (name != "" )
{
printChar( this , new key(name));
}
} while ( ! finish);
}
}
public class mm
{
public static void Main()
{
test a = new test();
a.printChar += new test.getKey(Consoles);
a.run( );
}
public static void Consoles( object sender,key e)
{
Console.WriteLine( " 输入,,,{0},{1},{2} " ,e.Name,((test)sender).EEEE,e.ToString());
}
}