I am writing a financial application where the concept of 'Price' is used a lot. It's currently represented by the C#
decimal type. I would like to make it more explicit and be able to change it to maybe
double in the future, so I was thinking of creating a 'Price' struct that would basically act exactly the same as the decimal type (maybe add a bit of validation like must be greater than 0).
What do you think are the pros and cons of doing this?
There shouldn't be a reason to change the data type for a quantity like this; however, you may decide to add other information such as the currency or the number of decimal places to keep track of in calculations, so using a struct at this point will save you a LOT of time down the road.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki