Hi,
Thanks for the help so far. I will give you a specific example I am
battling with...
File DataManipulation.cs
namespace WeatherStation
{
public class DataManipulation
{
public DataManipulation()
{
}
public void InitializeWeatherStationList()
{
List<WeatherlinkDll.SensorImageWeatherStationList = new
List<WeatherlinkDll.SensorImage>();
}
}
}
File WeatherStation.cs
namespace WeatherStation
{
public partial class formWeatherStation : Form
{
public void InitializeWeatherStation()
{
DataManipulation test = new DataManipulation();
test.InitializeWeatherStationList();
}
private void buttonTest_Click(object sender, EventArgs e)
{
test.WeatherStationList.Add(WeatherStationImage);
}
This gives error "The name 'test' does not exist in the current
context"
If I leave out the last line it compiles OK and I noticed that as soon
as I step out of InitializeWeatherStation() test is no longer
accessable which ties up with the error message. If I include all the
code in buttonTest_Click it works and the data is added to the list but
the list of course gets created every time. How do I sort this out?
I am new to C# coming from a embedded C background.
Thanks
SurfRat.
Peter Bradley wrote:
You need to reference BB in A.
You can then either create an instance of BB in A and call its methods, or
you can create an instance of BB somewhere else and pass it into A as a
parameter to a method in AA, or as a return value of a method in AA. Either
way, once you have an instance of BB, you can call methods on it.
Peter
<su******@hotmail.comwrote in message
news:11**********************@l53g2000cwa.googlegr oups.com...
Hi,
My project has about 4 source files (xxx.cs) and I am having a problem
with scope between the files. If I put the code all within one class
everything works OK. Can you please point me to some good resources
which explain scope on the file/class level.
What I want to do is as follows:
File A containing class AA
File B containing class BB
Access members of BB from A.
I am getting myself all twisted in knots :)
Thanks
SurfRat.