Coder World

November 11, 2007

structure in C#

Filed under: C# — Tags: , , — fookean @ 7:38 am

Things you need to know about structure.

1. It is a value type and placed on a stack (class allocated on the manage heap).

structureA tempstruct=new structureA(1,2)

strucureA tempstruct2=tempstruct.

One of the example of structure is System.Drawing.Point

When to use structure instead of class.

1. Will not be changed after creation.

2. Has an instance size less than 16bytes.

3. Logically represents a single valuye.

4. Will not be cast to a reference type.

If the value of tempstruct change, it will not affect tempstruct2 because they are allocated/pointing at different piece of memory.

Advertisement

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Theme: Silver is the New Black. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.