RemObjects Software Gears
 
       

Valuetypes in C#

{#} by Carlo Kok 05/26/04 08:50:55 pm, 178 words, Categories: main
After some confusion on IRC on the differences between classes and valuetypes (D8: records)
a valuetype in C# is a lot like a class, except that it a few differences:
  • It always decents from System.ValueType directly
  • It's always sealed (no other structure can decend from it)
  • Constructors, though possible are not called when you use them (speed reasons) unless explicitly called
The other difference, and also the most important one is the way it's stored. Structures are stored where you define them, which is different from classes because they are stored as a pointer and have to be created on the heap with the new operator. A reason to use structures instead of classes is usually speed, creating an array of structures is a single allocation for all items at once, when using classes, it's an allocation for the pointers, and for each item a seperate allocation for the class itself. One downside to valuetypes is that you can 't create subclasses and overriding methods is limited to the ones defined in System.ValueType and System.Object.

Comments, Pingbacks:

No Comments/Pingbacks for this post yet...

Leave a comment:

Your email address will not be displayed on this site.
Your URL will be displayed.

Allowed XHTML tags: <p, ul, ol, li, dl, dt, dd, address, blockquote, ins, del, span, bdo, br, em, strong, dfn, code, samp, kdb, var, cite, abbr, acronym, q, sub, sup, tt, i, b, big, small>
(Line breaks become <br />)
(Set cookies for name, email and url)
(Allow users to contact you through a message form (your email will NOT be displayed.))
This is a captcha-picture. It is used to prevent mass-access by robots.
Please enter the characters from the image above. (case insensitive)

 

Carlo Kok

Twitter

marc hoffman (follow)
    loading...
Mike Orriss (follow)
    loading...

Navigation

XML Feeds 

Who's Online?

  • Guest Users: 14