RE: Protected keyword
- From: Demetri <Demetri@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 18 May 2006 06:33:02 -0700
Only the Employee class internally can see the base class RaiseEvent method.
It is exposed through an instance of the class.
So if you did something like the following it would work:
public class Employee : Person
{
private bool heartIsBeating;
public void HoldBreath(){
while(true){
if(!heartIsBeating){
base.RaiseEvent("Heart stopped, deceased!");
break;
}
}
}
}
--
-Demetri
"Ant" wrote:
HI, I'm using the protected keyword in a class to make a method accessible to.
a child that inherits from it so as to be able to call the protected method
from the child class.
I can't seem to be able to access it from either the base class or the class
that inherits from it. Here is a sample of the code:
Any ideas would be most helpful.
Thanks in advance
Ant
public delegate void myDelegate(string message);
public class Person // The base class
{
// Constructor
public Person()
{
this.Deceased +=new myDelegate(Person_Deceased);
}
// Event
public event myDelegate Deceased;
// method to raise the deceased event
protected void RaiseEvent(string message)
{
this.Deceased(message);
}
// Event Handler
private void Person_Deceased(string message)
{
MessageBox.Show(message);
}
}
// class that inherits the Person class
public class Employee:Person
{
}
private void buttonClickEvent()
{
Employee emp = new Employee();
emp.RaiseEvent("Psycho"); // Get compile time inaccessible error here..
}
- Follow-Ups:
- RE: Protected keyword
- From: Demetri
- RE: Protected keyword
- Prev by Date: Re: Protected keyword
- Next by Date: Multithreading in GUI application
- Previous by thread: Re: Protected keyword
- Next by thread: RE: Protected keyword
- Index(es):