declarations - newbie question

declarations - newbie question

am 29.12.2007 05:14:40 von MS

This is from a learning project - never thought to ask these questions:

public partial class Form1 : Form

{

static String strFileName;

public PictureBox PictureBox1;

Bitmap bitmap = new Bitmap(strFileName);

QUESTION1 : What's the downside of static variables, memory usage? What
kind of scope does a static variable have?

QUESTION2: Why would I use the format that I use for "bitmap" instead of
the one for "PictureBox1"?

Vinnie.

RE: declarations - newbie question

am 29.12.2007 06:19:00 von PRSoCo

Static members have whatever scope you give them. By not explicitly
declaring the member with an access modifier (like public, protected,
private, internal) it defaults to private.

Static members are also called class members because they are "shared" to
the class (if private). They are essentially shared globally if public.

Static members essentially stick around for the life of the program, only
being collected upon exit, instance members will be collected whenever the
instance is collected. If you don't make use of a particular static, it will
needlessly occupy memory.

What difference in format are you talking about for the Bitmap and and
PictureBox? Are you talking about "public" on one and nothing (private) on
the other? I prefer to always include an access modifer, even if I'm using
what would otherwise be the default (private for members).

--
Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#


"MS" wrote:

> This is from a learning project - never thought to ask these questions:
>
> public partial class Form1 : Form
>
> {
>
> static String strFileName;
>
> public PictureBox PictureBox1;
>
> Bitmap bitmap = new Bitmap(strFileName);
>
> QUESTION1 : What's the downside of static variables, memory usage? What
> kind of scope does a static variable have?
>
> QUESTION2: Why would I use the format that I use for "bitmap" instead of
> the one for "PictureBox1"?
>
> Vinnie.
>
>
>