![]() |
| | #1 |
| Registered User Join Date: May 2005
Posts: 3
| accessing class variables sorry about another post but im new to OOP and i am having trouble understanding how i can access a variable from one class from a different class. I have a class Code: public class Main : System.Web.UI.Page
{
public string loadFile = " ";
.
.
public void Page_Load(object sender, System.EventArgs e)
{
loadFile = "test";
}
Code: public class Message : System.Web.UI.Page
{
Private void Page_Load(object sender, System.EventArgs e)
{
Main mc = new Main();
StreamReader sr = new StreamReader(mc.loadFile);
.
.
}
Thanks again guys |
| pug is offline | |
| | #2 |
| Banned Join Date: Feb 2003 Location: Australia
Posts: 986
| You've got a few choices.
Code: public class Main : System.Web.UI.Page
{
public static string loadFile = " ";
.
.
public void Page_Load(object sender, System.EventArgs e)
{
loadFile = "test";
}
--------------
public class Message : System.Web.UI.Page
{
Private void Page_Load(object sender, System.EventArgs e)
{
Main mc = new Main();
StreamReader sr = new StreamReader(Main.loadFile);
.
.
}
|
| nickname_changed is offline | |
| | #3 | |
| Registered User Join Date: May 2005
Posts: 28
| Quote:
Code: public class Main : System.Web.UI.Page
{
private string loadFile;
public Main()
{
loadFile = "test";
}
public string LoadFile
{
get
{
return loadFile;
}
}
}
--------------
public class Message : System.Web.UI.Page
{
Private void Page_Load(object sender, System.EventArgs e)
{
Main mc = new Main();
StreamReader sr = new StreamReader(mc.LoadFile);
.
.
}
Mezzano | |
| Mezzano is offline | |
| | #4 | |
| Banned Join Date: Feb 2003 Location: Australia
Posts: 986
| Quote:
There really are better ways to accomplish what he is trying to accomplish (whatever exactly that is) with better OO than creating another instance of an ASP.NET page in memory. | |
| nickname_changed is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Accessing a struct element in a different class... | Sparrowhawk | C++ Programming | 0 | 03-09-2009 04:24 PM |
| Global variables used in a linked class, getting errors. | RealityFusion | C++ Programming | 3 | 09-24-2005 12:25 AM |
| Static variables and functions problem in a class | earth_angel | C++ Programming | 16 | 09-15-2005 12:08 PM |
| My Window Class | Epo | Game Programming | 2 | 07-10-2005 02:33 PM |
| accessing Class members | fizisyen | C++ Programming | 3 | 01-07-2004 06:18 PM |