newbie question re: objects and scope
I don't think I quite follow you. Could you explain it in a little more detailed?
Sorry to be so dense.
I tried making a new class with constuctors for the object class, and called them in the method (that formerly held the constructors) from mainForm class, but they still ceased to exist outside the method that call the constuctor class...
I also made constuctor methods in the object class and call them from the mainForm method, but that didn't work either.
[475 byte] By [
mhorton] at [2007-12-16]
Play around with A, B, and C; this smaller example may help you see what's going on.using
System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main( string[] args ) {
C aClass = new C(); // local to Main
}
}
//==================================================
public class A
{
//==================================================
public A() {
Console.WriteLine( "constructing A" );
}
//==================================================
public void SayHi() {
Console.WriteLine( "Hi from A" );
}
}
//==================================================
public class B
{
private A localToB; // local to the B class
//==================================================
public B() {
localToB = new A();
}
//==================================================
public A ReturnTheAFromB() {
return localToB;
}
}
//==================================================
class C
{
//==================================================
public C() {
B b = new B(); // local to C constructor
A a = b.ReturnTheAFromB();
a.SayHi();
}
}
}
Thanks, that example helped a lot. I was able to modify my program to behave the same way. However I was still unable to get the program to work the way I wanted overall, I may just be going about it wrong from the start. Maybe I'm trying to do something beyond my current level of experience, so I'll come back to it later when I've learned more.