I'd like to better understand how the following code works. I've posted
questions below.
namespace Something.Somet hing1
{
using System;
public delegate void Test1();
public delegate void Test2(ink k);
public class A
{
public static void Log1 (int l)
{
Console.WriteLi ne(":{0}",l);
}
public void Log2 (int l)
{
Console.WriteLi ne("#{0}",l);
}
}
public class Class1
{
public static void Main()
{
A a = new A();
Test2 t0 = new Test2(A.Log1); //use static method
Test2 t1 = new Test2(a.Log2); //use instance method
t0 += t1; t0(0);
t0 -= t1; t0(1);
}
}
}
This will print ":0 #0 :1". How does Log1 print 0 when no param is passed
to it and "l" is not initialized to 0?
What are the differences in the static and instance method calls via
delegates?
This line t0 -= t1; t0(1); removes those methods from the delegate
collection correct? How is the output affected if that line does not
exists?
Also, if I'm using the IE object and have three successive page loads, will
each of the following events respectively fire after each page load rather
than all three always firing after each page load? In other words, after
the first page load completes, onIEDocComplete 1 fires. After the second
page load completes, onIEDocComplete 2 fires. After the third page load
completes, onIEDocComplete 3 fires.
IE_Inst.Documen tComplete += new
SHDocVw.DWebBro wserEvents2_Doc umentCompleteEv entHandler(this .onIEDocComplet e1);
IE_Inst.Documen tComplete += new
SHDocVw.DWebBro wserEvents2_Doc umentCompleteEv entHandler(this .onIEDocComplet e2);
IE_Inst.Documen tComplete += new
SHDocVw.DWebBro wserEvents2_Doc umentCompleteEv entHandler(this .onIEDocComplet e3);
Thanks,
Brett
questions below.
namespace Something.Somet hing1
{
using System;
public delegate void Test1();
public delegate void Test2(ink k);
public class A
{
public static void Log1 (int l)
{
Console.WriteLi ne(":{0}",l);
}
public void Log2 (int l)
{
Console.WriteLi ne("#{0}",l);
}
}
public class Class1
{
public static void Main()
{
A a = new A();
Test2 t0 = new Test2(A.Log1); //use static method
Test2 t1 = new Test2(a.Log2); //use instance method
t0 += t1; t0(0);
t0 -= t1; t0(1);
}
}
}
This will print ":0 #0 :1". How does Log1 print 0 when no param is passed
to it and "l" is not initialized to 0?
What are the differences in the static and instance method calls via
delegates?
This line t0 -= t1; t0(1); removes those methods from the delegate
collection correct? How is the output affected if that line does not
exists?
Also, if I'm using the IE object and have three successive page loads, will
each of the following events respectively fire after each page load rather
than all three always firing after each page load? In other words, after
the first page load completes, onIEDocComplete 1 fires. After the second
page load completes, onIEDocComplete 2 fires. After the third page load
completes, onIEDocComplete 3 fires.
IE_Inst.Documen tComplete += new
SHDocVw.DWebBro wserEvents2_Doc umentCompleteEv entHandler(this .onIEDocComplet e1);
IE_Inst.Documen tComplete += new
SHDocVw.DWebBro wserEvents2_Doc umentCompleteEv entHandler(this .onIEDocComplet e2);
IE_Inst.Documen tComplete += new
SHDocVw.DWebBro wserEvents2_Doc umentCompleteEv entHandler(this .onIEDocComplet e3);
Thanks,
Brett
Comment