If I want to access MyVariable
from Second
and Third
I could make MyVariable
protected. What if I want to access from Second
but NOT Third
. Is that possible?
Yes! Here's one technique:
class First
{
private int myVariable;
public class Second : First
{
public Second() { myVariable = 123; } // Legal!
}
}
class Third : First.Second
{
public Third() { myVariable = 456; } // Illegal!
}
Here's another:
// Alpha.DLL
public class First
{
internal int myVariable;
}
public class Second : First
{
public Second() { myVariable = 123; } // Legal!
}
// Bravo.DLL
class Third : Second
{
public Third() { myVariable = 456; } // Illegal!
}