Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

Explain about Protected and protected internal, ?internal?
access-specifier?

Answer Posted / ranganathkini

Protected access specifier implies that the class member is
accessible to other members of the same class or to members
of a class that derieves from the class the member
originates from. example:

namespace Ranga.AccessTest {
class ClassA {
protected void MethodA() {

}
}

class ClassB : ClassA {
public void MethodB() {
base.MethodA(); // invoke MethodA()
}
}

class ClassC {
public void MethodC() {
// ClassC is not subclass of ClassA
// Hence it cannot access MethodA
ClassA myA = new ClassA();
myA.MethodA(); // ERROR
}
}
}

Protected internal access-specifier implies that the class
member is accessible in its originating class as well as
other class in the same assembly (i.e. EXE or DLL ). This
means that the member's access is protected OR internal.
Example.

// The foll. classes will be compiled into Program1.dll
namespace Ranga.Program1 {
public class ClassA {
protected internal void MethodA() {

}
}

public class ClassB : ClassA {
public void MethodB() {
base.MethodA(); // invoke MethodA()
}
}

public class ClassC {
public void MethodC() {
// Since ClassC is now in the same assembly
// as ClassA, MethodA is now accessible to it
// as it is marked as protected OR internal
ClassA myA = new ClassA();
myA.MethodA(); // NO ERROR HERE
}
}
}

// The foll. classes will be compiled into Program2.exe
// add reference to Program1.dll while compiling
using Ranga.Program1;

namespace Ranga.Program2 {
class ClassD {
public void SomeMethod1() {
// ERROR because ClassD is not in the same
// assembly as ClassA, MethodA is not accessible
// to it.
ClassA myA = new ClassA();
myA.MethodA(); // ERROR
}
}

// Now observe this
class ClassE : ClassA {
public void SomeMethod2() {
// We can call MethodA of ClassA here
// though ClassE is in a different assembly
// it is a derieved class of ClassA, hence
// MethodA() becomes accessible to it.
base.MethodA() // NO ERROR HERE
}
}
}

Hope it helps!!!

Is This Answer Correct ?    52 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain nullable types in c#?

953


How can I access the registry from c# code?

1001


in the nunit test framework, which attribute must adorn a test class in order for it to be picked up by the nunit gui?

1143


What is data annotation in c#?

918


Is cli same as the clr?

876


What do you mean by serialization in .NET?

1006


How to sort an int array in c#?

928


Explain the Usage of web.config

991


What is the adv of using System.Text.StringBuilder over System.String?

953


Who is a accessibility modifier “protected internal” available to ?

998


How is a strongly-named assembly different from one that isn’t strongly-named?

1040


What is a datacontract?

917


What is tochararray in c#?

919


What is the default boolean value in c#?

939


What operators can be used to cast from one reference type to another without the risk of throwing an exception?

885