Calling a main loop object from a class method
Hey all, hopefully someone here can help. I have an object (a queue) that's created in the top of the main form class definition. I'm also creating several objects of a class. I need those class objects to submit to the queue. Unfortunately because of other considerations I'm going to have a hard time moving either the queue or the queue submission process. What's the syntax for submitting object from the class? Here's the pseudo code:
namespace Test1
{
public partial class Form1 : Form
{
public Handler Qlist = new Handler();
List Boxes = new List();
//main form methods, etc.
}
public class ClassObject
{
//variables, properties, etc
public void SendQueue()
{
//HERE is where I need to send to the items to Qlist
//How do I do that?
}
}
}
LeePosted Jun 11, 2008, 8:16 PM
C# has two types of variables: reference and value. Value variables represent a number or a value. Reference variables point to an object like a list or array or class or something. Passing a value as a parameter to a method actually passes a copy of that, changing it within the method doesn't alter the original. However passing a reference variable passes a pointer coming back to the original. Therefor, updating the pointer actually updates the original.
LeePosted Jun 11, 2008, 8:19 AM
So let me make sure I understand you... in the constructor for the child class I add a paramater for the parent to pass the queue. Then within the constructor I simply give the queue a local variable name?
Does that mean that when 15 different child class objects call this local variable name they are all referring to the object (the queue in this case) that exists at the parent level?
Jan MontanoPosted Jun 11, 2008, 1:21 AM
public class ClassObject
{
//variables, properties, etc
Handler qlist = null;
public ClassObject(Handler qlist){
this.qlist = qlist;
}
public void SendQueue()
{
//HERE is where I need to send to the items to Qlist
//How do I do that?
// qlist.AddItem ?
}
}