![]() |
| | #1 |
| Registered User Join Date: Aug 2006
Posts: 32
| Newbie Question I am trying to write some code in which one class, when it reaches a certain state, tells its parent class to do something: Code: class classA
{
classB B;
public classA()
{
B = new classB();
}
public functionA(){}
}
class classB
{
int x;
public functionB()
{
// Modifies the value of x in a random way
}
}
class Main
{
A = new classA();
A.B.functionB() /* This is called lots and lots, until x happens to equal 50. When x = 50, I want to dispose of B, and call A.functionA().*/
}
So, how can I tell A to do something once B reaches a certain state....could I use some sort of event handler, such that x=50 raises and event, thus telling A do dispose of B and so on? I am very new to C# and would like to know what the code for such an event handler would be, or any other suggestions on how I might implement this. Thank you! |
| ejohns85 is offline | |
| | #2 |
| Cat without Hat Join Date: Apr 2003
Posts: 8,492
| You have no choice. To react to x being 50, you have to test whether x is 50. Where you do it is irrelevant.
__________________ All the buzzt! CornedBee"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code." - Flon's Law |
| CornedBee is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Stupid Newbie question | TimL | C++ Programming | 4 | 07-22-2008 04:43 AM |
| C prog newbie question | Draginzuzu | C Programming | 1 | 02-03-2003 06:45 PM |
| a stupid question from a newbie | newcomer | C++ Programming | 4 | 01-11-2003 04:38 PM |
| confusion with integers (newbie question) | imortal | C Programming | 7 | 12-06-2002 04:09 PM |
| newbie class templates question | daysleeper | C++ Programming | 2 | 09-18-2001 09:50 AM |