Hi -
OK - this problem is about information flow between classes. Imagine I have
two hierarchically identical classes between which I want to pass some
variables (product of an internal method, say). I don't want to do the
following because TestClassII is a large form and it seems silly
instantiating such a large class just to get two variables from it:
using System;
namespace Test1
{
public class StartUp
{
public static void Main()
{
int xxx,yyy;
TestClassII tClassII = new TestClassII();
TestClassIII tClassIII = new TestClassIII();
tClassIII.xx = tClassII.x;
tClassIII.yy = tClassII.y;
xxx = tClassIII.xx;
yyy = tClassIII.yy;
Console.WriteLine("xxx = " + xxx);
Console.WriteLine("yyy = " + yyy);
}
}
public class TestClassII
{
public int x=1;
public int y=1;
public TestClassII()
{
}
}
public class TestClassIII
{
public int xx=0;
public int yy=0;
public TestClassIII()
{
}
}
Quote:
}
I would rather (erroneously or not, I don't know) use a third class as a
"postman" to send the variables from one class to another, something like
this:
using System;
namespace Test1
{
public struct Container
{
public int xa;
public int ya;
}
public class StartUp
{
public static void Main()
{
int xxx,yyy;
TestClassII tClassII = new TestClassII();
tClassII.MethodII();
TestClassIII tClassIII = new TestClassIII();
tClassIII.MethodIII();
xxx = tClassIII.xx;
yyy = tClassIII.yy;
Console.WriteLine("xxx = " + xxx);
Console.WriteLine("yyy = " + yyy);
}
}
public class TestClassII
{
public int x=1;
public int y=1;
public TestClassII()
{
}
public void MethodII()
{
Container cont = new Container();
cont.xa = x;
cont.ya = y;
}
}
public class TestClassIII
{
public int xx=0;
public int yy=0;
public TestClassIII()
{
}
public void MethodIII()
{
Container cont = new Container();
xx = cont.xa;
yy = cont.ya;
}
}
Quote:
}
However, the above doesn't work.Couldn't anybody put me straight here?
Many thanks,
Chris.