On Apr 10, 5:22 pm, Eran.Ya...@gmai l.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.WriteLi ne( "printmeA() ");}
printmeB()
{
Console.WriteLi ne( "printmeB() ");}
printmeC()
{
Console.WriteLi ne( "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.Collecti ons.Generic;
using System.Text;
namespace ConsoleApplicat ion1
{
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.print meA );
callb( d,"1" );
d = new WriteMeCallback ( AsyncMain.print meB );
callb( d , "2" );
d = new WriteMeCallback ( AsyncMain.print meC );
callb( d , "3" );
}
}
}
my question is if the line "d = new
WriteMeCallback ( AsyncMain.print meB );" is correct.