Why is System.DateTime a structure?

  • Thread starter Thread starter Pram
  • Start date Start date
P

Pram

I am curious why did Microsoft write System.DateTime as a structure instead
of a class?

Maybe for backward compatibilty with any existing old code?

FYI, one of the differences between structure and class is we can set the
structure to Nothing.
 
Sorry it should be:
one of the differences between structure and class is we can NOT set the
structure to Nothing.
 
* "Pram said:
I am curious why did Microsoft write System.DateTime as a structure instead
of a class?

Maybe for backward compatibilty with any existing old code?

FYI, one of the differences between structure and class is we can set the
structure to Nothing.

Why is a 'Point' a structure? Why a 'Rectangle'? I think that most of
the structures in the .NET framework have two things in common: They are
very simple, use mostly simple datatypes (value types) and when working
with them often copies of the objects are created.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

Improve your quoting style:
<http://learn.to/quote>
<http://www.plig.net/nnq/nquote.html>
 
Pram,
I believe DateTime is a structure, as it meets all the criteria to use when
deciding to make a type a Structure as set forth by the .NET Design
Guidelines for Class Library Developers, in that it:

- Acts like a primitive type
- It has an instance size of under 16 bytes
- It is immutable
- It has value semantics.

Which is 4 for 4!

http://msdn.microsoft.com/library/d...genref/html/cpconvaluetypeusageguidelines.asp

The one item that is not listed, but is implied by the above list is as a
Structure it is significantly easier to work with as opposed to being a
class!

Hope this helps
Jay
 
Back
Top