T
Tan
C# does not offer the keyword "Friend" (C++ has it). Is there anyway that I
can emulate this ?
namespace myclass{
public class A
{
protected virtual void Add()
{
}
}
public class B:A
{
private StringCollection MyCollection;
protected virtual void Add()
{
//Add item into MyCollection
}
public StringCollection _MyCollection
{
get { return MyCollection; }
}
}
public class C
{
public DoSomeWorks()
{
B b = new B();
//Call 'friend' functions in B so that B:Add() protection function
get called.
}
}
namespace Test
{
public static void Main(..)
{
C c = new C();
c.DoSomeWorks();
}
}
The idea is to allow C:
oSomeWorks() to call B:Add() protected virtual
function so that data can be added to MyCollection, and thus make
MyCollection remains "readonly" to outsider.
One way is to have class C inherits from class B (something that I am try to
avoid). Can anyone help ? Thanks.
can emulate this ?
namespace myclass{
public class A
{
protected virtual void Add()
{
}
}
public class B:A
{
private StringCollection MyCollection;
protected virtual void Add()
{
//Add item into MyCollection
}
public StringCollection _MyCollection
{
get { return MyCollection; }
}
}
public class C
{
public DoSomeWorks()
{
B b = new B();
//Call 'friend' functions in B so that B:Add() protection function
get called.
}
}
namespace Test
{
public static void Main(..)
{
C c = new C();
c.DoSomeWorks();
}
}
The idea is to allow C:

function so that data can be added to MyCollection, and thus make
MyCollection remains "readonly" to outsider.
One way is to have class C inherits from class B (something that I am try to
avoid). Can anyone help ? Thanks.