HighTechTalks DotNet Forums  

declarations - newbie question

Dotnet General Discussions microsoft.public.dotnet.general


Discuss declarations - newbie question in the Dotnet General Discussions forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
MS
 
Posts: n/a

Default declarations - newbie question - 12-28-2007 , 11:14 PM






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.



Reply With Quote
  #2  
Old   
Peter Ritchie [C# MVP]
 
Posts: n/a

Default RE: declarations - newbie question - 12-29-2007 , 12:19 AM






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:

Quote:
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.




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.