On Apr 10, 5:22 pm, Eran.Ya...@gmail.com wrote:
Hi,
I saw that there's the delegate feature that handles as pointer to
function but in safe mode.
Can I send function name to other function to call it?
for example:
printmeA()
{
Console.WriteLine( "printmeA()");}
printmeB()
{
Console.WriteLine( "printmeB()");}
printmeC()
{
Console.WriteLine( "printmeC()");}
function B(object Calledfun)
{
Calledfun();}
function A()
{
B(printmeA);
B(printmeB);
B(printmeB);
}
thanks.
Ok just found the solution. Hope It is ok how I did it:
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
public class AsyncMain
{
private delegate void WriteMeCallback( string Message );
private static void printmeA( string msg )
{
Console.Write( "printmeA()" + msg );
}
private static void printmeB( string msg )
{
Console.Write( "printmeB()" + msg );
}
private static void printmeC( string msg )
{
Console.Write( "printmeC()" + msg );
}
private static void callb( WriteMeCallback d,string msg )
{
d.Invoke( msg );
}
public static void Main()
{
WriteMeCallback d = new WriteMeCallback( AsyncMain.printmeA );
callb( d,"1" );
d = new WriteMeCallback( AsyncMain.printmeB );
callb( d , "2" );
d = new WriteMeCallback( AsyncMain.printmeC );
callb( d , "3" );
}
}
}
my question is if the line "d = new
WriteMeCallback( AsyncMain.printmeB );" is correct.