How do I define a class to be accessible from other classes.
Hello
I have a class called CHardware.
I would like to define this class once as:
CHardware hardware = new Hardware();
Then be able to access hardware from any where in my program. Such as from within other classes.
How do I do that.
David
You should search the web for Object Oriented Programming.
But anyway, I suspect you have a class
namespace MyApplication.Objects
public class Hardware
{
// default constructor
public Hardware()
{
}
//properties
//methods
}
From another class if this class is in the same solution at the top of your code indicate
using MyApplication.Objects
now you can say:
Hardware myHardware = new Hardware();
If this class is in a separate dll then you have to add it as a reference, and use the same code.
Hello
No that is not what I mean.
If I declare my hardware class as above
CHardware hardware = new Hardware();
in FormMain
publicpartialclass
FormMain : Form {
CHardware HardWare1 = new
CHardware();CHardware HardWare2 = newCHardware();
public FormMain(){
InitializeComponent();
}
So I can call Hardware1.AnyMethod() from within FormMain.
But what I want to do is call Hardware1 from within another class, such as another form without having to declare it again.