| re: Variables passing problem
Hi Reinier,
In the method public static void Example() you cannot call
ClassB.method1( ); as method1() is not a static method of class B , you have
basically two options:
1- Create a new instance of ClassB either inside Example() or make it a
variable of class classA.
2- declare ClassB.method1() as static, in this solution you will also have
to declare static the instance of class C static ClassC c= new ClassC();
Hope this help,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Reinier Beeckman" <rjlbeeckman@hotmail.com> wrote in message
news:emNXx7tdDHA.3232@TK2MSFTNGP10.phx.gbl...[color=blue]
> Hi,
>
> In a program i'm working on i got several classes. 3 of them have relation[/color]
to my[color=blue]
> problem. Let's name them classes class A, class B and class C.
>
> classA
> {
> public static ClassA A = new ClassA( );
>
> public static void Main()
> {
> Example();
> }
>
> public static void Example()
> {
> ClassB.method1( );
> //QUESTION:
> //here i want to call the variables set in class B, but i[/color]
can't do[color=blue]
> that since Class B is not know
> //in class A. When i say "public static ClassB b = new ClassB[/color]
a new[color=blue]
> "empty" class is made for ClassC
> //which does not contain the variables i want.
> //How can i ask the needed variables from ClassC in ClassA[/color]
????[color=blue]
>
> //I do not want to set the variables in ClassA, i really need[/color]
and[color=blue]
> want this construction !
> }
> }
>
> ClassB
> {
> ClassC c = new ClassC( )
> public void method1( )
> {
> c.setVariableA("testValue1");
> c.setVariableB("testValue2");
> }
> }
>
> ClassC
> {
> string variableA, variableB;
>
> public void setVariableA(string var1)
> {
> this.variableA = var1;
> }
>
> public void setVariableB(string var2)
> {
> this.variableB = var2;
> }
>
> public string getVariableA( )
> {
> return VariableA;
> }
>
> public string getVariableB( )
> {
> return VariableB;
> }
> }
>
>[/color] |