Object Orientated global problem

S

Steven Blair

Hi,

I have several classes which need to access the same object (a dll). What is
the best way of achieving this?
In C++ I would just have a pointer in a library and #include that library to
all my classes, but obviously cant do this in C#.

I have tried making the object static inside one of my classes and allowed
my other class to speak to the object:

frmMain.m_MyObject.SomeMethod();

I not sure if this is very efficient, or the best way to achieve this.

I was also advised to use something called a Singleton, but to be honest
that gives me the same problem as before:

Singleton.MyObject.SomeMethod();

I am hoping there is a way to mark a variable as global to a whole
namespace, which doesnt require a class to speak to the object.

Any help on this would be appreciated.

Regards,

Steven
 
F

fbhcah

Why exactly do u feel using static is inefficient?

Every field/properties/methods are defined in a class in C#. So you need
to have a class to qualify the entity. And if you need to make it
global, make it static.

HTH,
fbhcah
 
S

Steven Blair

I wasnt sure if using static was inefficient, thats one of the reasons why I
was asking.

Thanks for the reply

Regards,

Steven
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top