P
puzzlecracker
Sort of new to internal of delegates.
My question is when you create a delegate instance, does the
surrounding block must be able to see/access method you want delegate
to take on. Here is concrete example:
namespace Test
public delegate string MyDelegate (int x);
class A {
private string IamPrivate(int x)
{
System.WriteLine("I am private {0}, get lost!",x);
}
}
class B{
private MyDelegate _d = new MyDelegate (Test.IamPrivate);
public void Foo()
{
d(10);
}
}
If this is allowed (hopefully not), anyone with ease can circumvent
the encapsulation of csharp. Is it?
Well, in nutshell, I am trying to better understand delegate/events in
the context of a class access level. Explanations are welcome.
Thanks
My question is when you create a delegate instance, does the
surrounding block must be able to see/access method you want delegate
to take on. Here is concrete example:
namespace Test
public delegate string MyDelegate (int x);
class A {
private string IamPrivate(int x)
{
System.WriteLine("I am private {0}, get lost!",x);
}
}
class B{
private MyDelegate _d = new MyDelegate (Test.IamPrivate);
public void Foo()
{
d(10);
}
}
If this is allowed (hopefully not), anyone with ease can circumvent
the encapsulation of csharp. Is it?
Well, in nutshell, I am trying to better understand delegate/events in
the context of a class access level. Explanations are welcome.
Thanks