using System;
using System.Collections.Generic;
using System.Text;
namespace delegate_function
{
public class mydelegates
{
public delegate void DAM(string str);
// delegates first or constructor first
// for the class constructor will be the first one to evoked
//public mydelegates() { Console.WriteLine("Constructor evoked"); }
//~mydelegates() { Console.WriteLine("Destructor evoked"); }
//create a method with delegate
private string m_name = "N/A";
public string Name
{
get
{
return m_name;
}
set
{
m_name = value;
}
}
public void process_request(DAM input)
{
if (input != null)
{
input(m_name);
Console.WriteLine("P-R > First Process done : ");
Console.WriteLine("----------------------------------- ");
}
if (input != null)
{
DateTime showtime = DateTime.Now;
input("m_name");
Console.WriteLine("P-R > Second Process done { 0:m } : " + showtime);
Console.WriteLine("----------------------------------- ");
Console.WriteLine();
}
}
public static void call_process(string s)
{
if (s == "Manas")
{
Console.WriteLine(" Call Pro > You have admin right : " + s);
}
else
{
Console.WriteLine(" Cal Pro > Thanks for visiting " );
}
}
public override string ToString()
{
return Name ;
}
}
public class multicast
{
mydelegates mg = new mydelegates();
public static void admin(string ns)
{
if (ns == "Manas")
{
mydelegates mm = new mydelegates();
mm.Name = ns;
Console.WriteLine("---------------------------------------- ");
Console.WriteLine("Admin > Input Checked You are an admin: " + ns);
Console.WriteLine("---------------------------------------- ");
}
}
class test
{
static void Main(string[] args)
{
multicast myc = new multicast();
mydelegates myd = new mydelegates();
mydelegates.DAM d_a_m = null;
d_a_m += new mydelegates.DAM(mydelegates.call_process);
d_a_m += new mydelegates.DAM(multicast.admin);
Console.Write(" Enter something : ");
string str = Console.ReadLine();
multicast.admin(str);
myd.process_request(d_a_m);
Console.Write(" Hit Enter to Quit : ");
Console.ReadLine();
}
}
}
}
|