Home All Groups Group Topic Archive Search About

Strong Typing of Primitive Types

Author
10 Mar 2005 6:25 PM
DavidNJ
We would like to create strong types to provide more compile time error
control. For example we would like salary to be from a salary class,
temperature to be from a temperature class, age to be from an age class, etc.

However, these would be have like decimals, integers, etc.

Are there classes hiding somewhere like 'Integer', 'Decimal', etc. that
would allow an inherited class to be derived that had all the behavior of the
primative type but was type safe?

Thanks,

David
Author
10 Mar 2005 7:19 PM
Marcos Stefanakopolus
Maybe I'm missing something, but why not just wrap the primitive types with
your own names?

class Salary : decimal {
    // look, Ma, no work necessary!
}



Show quoteHide quote
"DavidNJ" <Davi***@discussions.microsoft.com> wrote in message
news:D748FE18-F68C-4857-B63D-D480D9676909@microsoft.com...
> We would like to create strong types to provide more compile time error
> control. For example we would like salary to be from a salary class,
> temperature to be from a temperature class, age to be from an age class,
> etc.
>
> However, these would be have like decimals, integers, etc.
>
> Are there classes hiding somewhere like 'Integer', 'Decimal', etc. that
> would allow an inherited class to be derived that had all the behavior of
> the
> primative type but was type safe?
>
> Thanks,
>
> David
Are all your drivers up to date? click for free checkup

Author
10 Mar 2005 8:05 PM
Mattias Sjögren
Marcos,

>Maybe I'm missing something, but why not just wrap the primitive types with
>your own names?
>
>class Salary : decimal {

You can't derive from value types.



Mattias

--
Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Bookmark and Share