Hello everyone,
When dealing with value types, I met with two conflicting points,
1. We can not inherit one value type from another, for example, we can not make a struct inherit from another struct; -- I think it means there is no inheritance or derivation for value types.
2. All value types are inherits from ValueType, and ValueType is inherits from Object, seems value types could have inheritance or derivation?
How do you understand the two conflicting points? :-)
thanks in advance,
George

AlanRank #669 · 3.6K reputationPosted May 8, 2008, 11:56 AM EDT
1. No you can't derive from a struct.
2. ValueType from which all structs derive is in fact an abstract class, not a struct, so there's no inconsistency here.
George GeorgeRank #1,736 · 870 reputationPosted May 8, 2008, 11:55 PM EDT
Thanks Alan,
One further question, I think for primitive types, there are pairs of relationship, example int and Int32 are the same thing, only different in names. Is my understanding correct (I can not find answers from any books or search)?
regards,
George
Awadhesh Pratap6 reputationPosted May 9, 2008, 1:57 AM EDT
Both are the same struct ( represnting 32 bit Integer )
System.Int32
I think int is a shorthand for writing Int32 which is one of the available integer type.
Int16
Int32
Int64
George GeorgeRank #1,736 · 870 reputationPosted May 9, 2008, 2:13 AM EDT
Thanks Awadhesh,
Question answered.
regards,
George