Easy object question

  • Thread starter Thread starter AMP
  • Start date Start date
A

AMP

Hello,
I want to use a ready made class (ie a System.Drawing .Pen) and make it
available to my entire application, but I'm getting stupid.
How do I do this? Or point me in the right direction.
Thanks
 
AMP said:
Hello,
I want to use a ready made class (ie a System.Drawing .Pen) and make it
available to my entire application, but I'm getting stupid.
How do I do this? Or point me in the right direction.
Thanks

What do you mean by "it". Do you mean the class, or an instance of that
class? I'm guessing that you mean an instance...?
 
Hi,

You can create a static member variable and property in a class and make it
public, it will be accessible from all places using className.PropertyName

Now, IIRC a Pen consume unmanaged resources, that you should not keep a hold
on unless you really need it. IMO it would be better if you create it only
when needed and destroy it right after.
 
Yes, an instance.
Thanks
Mike
Bruce said:
What do you mean by "it". Do you mean the class, or an instance of that
class? I'm guessing that you mean an instance...?
 
Something like this?

I have a class called UnitOfMeasure that represents... well, a unit of
measure. There are several units of measure that I use all over the
system, such as LinearFeet:

public class UnitOfMeasure
{
private static _linearFeet = new UnitOfMeasure(... arguments to
make a "linear feet" instance ...);

public static UnitOfMeasure LinearFeet
{
get { return this._linearFeet; }
}
}

then whenever I need linear feet, I just say: UnitOfMeasure.LinearFeet.
 

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

Back
Top