F
Frank Rizzo
Any ideas?
Any ideas?
extend (inherit from) it.<Because System.DateTime is a sealed class which means that you cannot
Frank Rizzo said:Any ideas?
Frank Rizzo said:Any ideas?
boxing, structs are faster and smaller which is why all the primatives areYou forgot one - and this is the reason for their existance - With no
Joanna Carter (TeamB) said:"Richard Blewett [DevelopMentor]" <[email protected]> a écrit
dans
le message de news: #[email protected]...boxing, structs are faster and smaller which is why all the primatives areYou forgot one - and this is the reason for their existance - With no
valuetypes and things like System.Drawing.Point
boxing, structs are faster and smaller which is why all the primatives areYou forgot one - and this is the reason for their existance - With no
boxing, structs are faster and smaller which is why all the primatives areRichard Blewett said:You forgot one - and this is the reason for their existance - With no
Regards
Richard Blewett - DevelopMentor
Richard Blewett said:The boxing will only occur if you pass the value to a method that takes
System.Object, if you take an interface based reference or you call one of
the System.Object virtual methods that you haven't overridden.
Regards
RichGK said:boxing, structs are faster and smaller which is why all the primatives are
valuetypes and things like System.Drawing.Point
So why make DateTime a struct? Its not what I'd consider a primitive.
I think structs will be more used in .NET 2.0 as generic types as List<T>
and such will cope with the boxing problem. When this happens I think people
will use structs for business entities and data entities, and not interfaces
as Java typically does things.
I'd rather see a Customer as a struct and not an class or interface. The
struct says - "I am a customer and I do this and that and I am written in
stone so you can always expect the same behavour from me!" I think this
makes more sense than having an class go: - "I am perhaps a customer or
something more special than that and I may do what you expect if not
something completly overriden.
" Interfaces though are worst in my view: - "I
am sorta like a customer and I behave in a customerlike way. But exactly
what I do is hidden from you and may change at anytime depending on the
factory that (perhaps) loaded me dynamically. You'll never know!"
In of .NET 1.1, I don't use structs for the above purposes as it's
performance problem in regards to boxing is quite costly.
Michael S said:I think it is very much a primitive. The rules for Dates and Time is quite
clear and there is no need for polymorphism. People who use the DateTime
struct will know exactly how it behaves and nobody can change it's behavour.
It would be not so cool if you could subclass a DateTime and make that count
with Marsion dates and time. Other classes that depends on Tellus date and
time would be mighty confused. The great thing about structs is that you can
rely on them to behave exactly the same. Not in an assembly, not in a
solution, but over the whole platform (.NET).
The problem with .NET 1.1 is the boxing/unboxing performance hit.
Richard Blewett said:The boxing will only occur if you pass the value to a method that takes
System.Object, if you take an interface based reference or you call one of
the System.Object virtual methods that you haven't overridden.
Regards
A struct inherits from System.ValueType (which inherits from Object).A class is inheritable. A struct is implicitly sealed and always inherits
from Object. (This answers your question)
A struct can be boxed into a System.ValueType variable in addition to anA class can be cast to itself and to any superclass of it's type. A struct
can only be boxed into Object and unboxed to it's sealed type.
Where structs are needed (such as System.Int32) they are a beautiful thing &A class is a beautiful thing. structs sucks! =)
Jay B. Harlow said:Where structs are needed (such as System.Int32) they are a beautiful thing
& classes sucks!!![]()
There are numerous structs that we "need" that the framework does notBut .NET allready serves us with the structs we need, like Int32 and
Point.
Are you certain?Trust me; an System.Int32 is NOT a ValueType.
Are you certain? DateTime is Implemented as a (long) Integer that is theAn actual DateTime instance is a double on the Intel FPU stack.
Jay B. Harlow said:(C.E.) in the GregorianCalendar. Why involve the FPU? You're not thinking
of how a COM DateTime was implemented as a Double are you?
??- ValueTypes in the system namespace can freely be optimized by the
jitter, but all other ValueTypes will be compiled as written.
Naturally!For most applications; the boxing/unboxing is a problem that will soon
have it's remedy with generics.
Michael S said:Indeed Jay.
But .NET allready serves us with the structs we need, like Int32 and Point.
The great part with .NET and especially C# is that it does not settle with -
"It's a primitive, they are special", as in Java; but actually can describe
a Intel 32-bit register as a ValueType with methods and operators. This is
why I love C# so much that I have (almost) given up on Delphi.
It's all for show though.
ValueTypes in the System namespace is part of the Common Type System (CTS)
as per defined by the ECMA- and ISO-standards and hence the jitter (JITC)
can optimize them. Trust me; an System.Int32 is NOT a ValueType. Once
running, it's a 32-bit in register or on a stack.
When you add two Int32 no overloaded method is actually called.
An actual DateTime instance is a double on the Intel FPU stack.