alright, let me try and explain this:
I have a main class that creates new instances of two other classes (class 1, class 2)
"class 1" needs to do a lot of work with info from "class 2", but unfortunately can't access it. I could pass it all in as parameters from the main class (which obviously can acess both "class 1" and "class 2" as it created them), but this would be insanely difficult ( due to how much stuff it works with).
I thought that i could simply create a public version of class 2 in the code for the main class by saying
public classname Class2
(
get { return class2; }
set { class2 = value; }
)
I then tried to access "class 2" in "class 1"'s code by saying main.Class2.blahblah but intellisense didnt pop up with an option for Class2, so i guess this wasnt the way to do it.
how can I make these classes accessable by eachother (by the way, is there a more complex book that I can get on this subject I think im growing beyond the scope of my visual c# 2005 step by step book!)
thanks

still not getting communication between classes
MAyotte
Can you post small piece of code from both the classes in form of:
public class Class1
{
string someProperty;
public string SomeProprty
{
get{ return someProperty;}
}
//////////////////////////
}
What actually you are not getting from other class Make sure what you are trying to reference is not market with static and/or private keywords.
Best Regards,
MurrayLang
Ben Vanik
Thanks very much everyone
keptin
public class main
{
private galaxSetup gcGalaxSetup = null;
private ai gcShipAI = null;
//blah blah blah
gcGalaxSetup=new galaxSetup();
gcShipAI = new ai();
public galaxSetup Ggalaxsetup //apparently didnt do what i wanted it to
{
get { return gcGalaxSetup; }
set { gcGalaxSetup = value; }
}
}
public class ai
{
public void dispatch()
{
//do things with gInSystem by calling Ggalaxsetup.gInSystem but this didnt work!
}
}
public class galaxSetup
{
List<int> inSystem = new List<int>();
//some numbers are added to inSystem
public List<int> gInSystem
{
get { return inSystem; }
set { inSystem=value; }
}
}
alright so the idea is that the main class creates "gcGalaxSetup and "gcShipAI". The main class then goes to a method (which i didnt include) in gcGalaxSetup which stores some information to the "inSystem" variable. After this is done, the main class then goes to gcShipAI.dispatch(); This method is supposed to read some numbers from the inSystem variable, but I can't figure out how to do that. I attempted to make gcGalaxSetup public through Ggalaxsetup in the main class, but i cant access this in gcShipAI like i thought i could.
hope that clears it up a bit
Joshua Baker
tody4
If the main class creates class 2, then it has a reference to it. eg:
class2 c2 = new class2();
Now, main can create class 1 and pass this in eg.
class1 c1 = new class1(c2);
Now class 1 has a reference to class 2.
ELADDDDDDDA
I haven't tried it myself, but i guess this should work:
public class main
{
private galaxSetup gcGalaxSetup = null; private ai gcShipAI = null;//blah blah blah
gcGalaxSetup=
new galaxSetup();gcShipAI =
new ai(gcGalaxSetup);}
public
class ai{
private galaxSetup _galaxSetup; public ai(galaxSetup objGalaxSetup){
_galaxSetup = objGalaxSetup;
}
public void dispatch(){
_galaxSetup.gInSystem.items.add(5);
}
}
public
class galaxSetup{
List<
int> inSystem = new List<int>(); //some numbers are added to inSystem public List<int> gInSystem{
get { return inSystem; } set { inSystem=value; }}
}