I can understand how protected modifier will work for class members(methods and variables), but anyone please tell me how Protected class will behave.
eg:-
namespace AssemblyA
{
Protected class ProClass
{
int a=10,b=10;
public int get()
{
return a+b;
}
}
}
Can anyone please explain how the protected class will behave.
It will fail to compile, the way you've written it. Only nested classes can be protected - and they're accessible to any classes derived from the outer class, just like other protected members.
class Outer
{
protected class Nested
{
}
}
class Derived : Outer
{
static void Foo()
{
var x = new Outer.Nested(); // Valid
}
}
class NotDerived
{
static void Foo()
{
var x = new Outer.Nested(); // Invalid
}
}
See more on this question at Stackoverflow