473,403 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Variables passing problem

Hi,

In a program i'm working on i got several classes. 3 of them have relation to my
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 can't do
that since Class B is not know
//in class A. When i say "public static ClassB b = new ClassB a new
"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 ????

//I do not want to set the variables in ClassA, i really need and
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;
}
}
Nov 15 '05 #1
1 1210
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" <rj*********@hotmail.com> wrote in message
news:em**************@TK2MSFTNGP10.phx.gbl...
Hi,

In a program i'm working on i got several classes. 3 of them have relation to my 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 can't do that since Class B is not know
//in class A. When i say "public static ClassB b = new ClassB a new "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 ????
//I do not want to set the variables in ClassA, i really need and 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;
}
}

Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Amr Mostafa | last post by:
Hello :) I'm trying to write a script that deals with a web service. I'm using NuSoap class. my question is : Can I pass some variables By Reference to the web service and get the result back...
5
by: Jack | last post by:
Hi, I need to pass multple variables in a link in order to go to a asp page with the two varables. The following are the values of the variables using response.write: <%'Response.Write Mypage...
7
by: Michael | last post by:
Hi newsgroup, as the subject indicates I am looking for an advice using global variables. I am not if this problem is more about style then C. If its wrong in thi group, sorry. So I have a...
9
by: William LaMartin | last post by:
I have a problem, mentioned here before, of Session and Application variables disappearing at one site but not at others or on my development computer. The problem is illustrated by an example...
10
by: Goran Djuranovic | last post by:
Hi all, Does anyone know how to declare a variable in a class to be accessible ONLY from a classes instantiated within that class? For example: ************* CODE ***************** Public...
18
by: BillE | last post by:
When a user opens a new IE browser window using File-New-Window the integrity of an application which relies on session state is COMPLETELY undermined. Anyone who overlooks the fact that...
7
by: misha | last post by:
Hello. I was wandering if someone could explain to me (or point to some manual) the process of mapping the addresses of host variables by DB2. Especially I would like to know when DB2 decides to...
55
by: Zytan | last post by:
I see that static is more restricted in C# than in C++. It appears usable only on classes and methods, and data members, but cannot be created within a method itself. Surely this is possible in...
8
by: David Veeneman | last post by:
Should a member variable be passed to a private method in the same class as a method argument, or should the method simply call the member variable? For years, I have passed member variables to...
1
weaknessforcats
by: weaknessforcats | last post by:
C++: The Case Against Global Variables Summary This article explores the negative ramifications of using global variables. The use of global variables is such a problem that C++ architects have...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.