By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,219 Members | 2,147 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,219 IT Pros & Developers. It's quick & easy.

Extend System.Decimal?

P: n/a
Is there any way to extend or write a own "System.Decimal"?

In the doc its declared as
<Serializable>
Public Structure Decimal
Implements IFormattable, IComparable, IConvertibleBut how do you get the
functionallity that you can do Dim x as mydecimalx = 100Is that possible or
can only microsoft do stuff like that?RegardsFredrik
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Frederik,

In my opinion can you create any class that holds the methods to do what you
want, however not create a new value type.

Cor

Nov 21 '05 #2

P: n/a
Fredrick,
Decimal, being a Structure is a value type, which work the same as
NotInheritable Classes. Which means you cannot extend it directly, you would
need to encapsulate it and delegate all the methods to the real structure.

You can define MyDecimalX as a Structure and it will have all the value type
semantics of the Decimal type. However you will need to wait for VS.NET 2005
(aka Whidbey, due out in 2005) to support overloaded operators. Which will
allow your MyDecimalX to support +, -, /, * and other operators that you
define.

For a quick intro to overloading operators in VB.NET see:

http://blogs.gotdotnet.com/cambecc/p...1-127195cceeab

Overloading operator CType allows you to define custom conversions, for
example Decimal to & from MyDecimalX, allowing:

Dim d As Decimal
Dim md As MyDecimalX
d = md ' Widening Operator CType
md = CType(d, MyDecimalX) ' Narrowing Operator CType

FYI: VB.NET 2002 & 2003 knows about the Decimal type, so we are currently
able to use its overloaded operators directly. With VB.NET 2005 we will be
able to make use of the overloaded operators on any type in the Framework,
such as DateTime & TimeSpan.

Hope this helps
Jay

"Fredrik Melin" <me*@n.o.spam.dacsa.net.remove.as.needed> wrote in message
news:ex**************@TK2MSFTNGP12.phx.gbl...
Is there any way to extend or write a own "System.Decimal"?

In the doc its declared as
<Serializable>
Public Structure Decimal
Implements IFormattable, IComparable, IConvertibleBut how do you get the functionallity that you can do Dim x as mydecimalx = 100Is that possible or can only microsoft do stuff like that?RegardsFredrik

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.