1
Answer

Need to Know Internal modifier & protected Internal with complte example with assembly?

Photo of karthik e

karthik e

15y
3k
1
i am confussed about internal and protected internal . I need complete example with code . 
Thanks

Answers (1)

0
Photo of Hirendra Sisodiya
NA 8.8k 3m 15y

if you make it protected , only derived classes (of even another Assembly) can access the member and if you make it internal , only classes (either derived or not) of the same Assembly can access the member
Suppose that
namespace Country
{
public class State
{
// Declare three methods protected internal,protected and internal inclass state of Country library
protected internal void City1
{
// Code
}
protected void City2
{
// Code
}
internal void City3
{
// Code
}
}
// drive new class District from state
public class District : State
{
public District()
{
// we can access all three methods..
City1();
City2();
City3();
}
}
public class Highway
{
public static void Main()
{
State cls = new State();
cls.City1();
cls.City3();
//----------------------------------------
cls.City2();
//--Here we cant access Prtotected Method
//----------------------------------------------
}
}
}

// now wetake an another class library

namespace
Water
{
public class River : State
{
public void Main()
{
cls.City1();
cls.City3();
//--Here we cant access internal method
}
}
}

that means protected internal; only derived types or types within the same assembly can access that member, so they need to be in the same Dynamic Link Library or an executable file.
hope your confusion hasbeen cleared
thanks
Please mark as answere if it helps