Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 580499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:28:47+00:00 2026-05-13T14:28:47+00:00

I was reading a Business Primitives by CodeBetter.com and was toying around with the

  • 0

I was reading a Business Primitives by CodeBetter.com and was toying around with the idea.

Taking his example of Money, how would one implement this in a way that it can be used similarily as regular value types?

What I mean by that is do this:

Money myMoney = 100.00m;

Instead of:

Money myMoney = new Money(100.00m);

I understand how to override all the operators to allow for functionality doing math etc, but I don’t know what needs to be overriden to allow what I’m trying to do.

The idea of this is to minimize code changes required when implementing the new type, and to keep the same idea that it is a primitive type, just with a different value type name and business logic functionality.

Ideally I would have inherited Integer/Float/Decimal or whatever required, and override as needed, however obviously that is not available to structures.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T14:28:47+00:00Added an answer on May 13, 2026 at 2:28 pm

    You could provide an implicit cast operator from decimal to Money like so:

    class Money {
        public decimal Amount { get; set; }
        public Money(decimal amount) {
            Amount = amount;
        }
        public static implicit operator Money(decimal amount) {
            return new Money(amount);
        }
    }
    

    Usage:

    Money money = 100m;
    Console.WriteLine(money.Amount);
    

    Now, what is happening here is not that we are overloading the assignment operator; that is not possible in C#. Instead, what we are doing is providing an operator that can implicitly cast a decimal to Money when necessary. Here we are trying to assign the decimal literal 100m to an instance of type Money. Then, behind the scenes, the compiler will invoke the implicit cast operator that we defined and use that to assign the result of the cast to the instance money of Money. If you want to understand the mechanisms of this, read §7.16.1 and §6.1 of the C# 3.0 specification.

    Please note that types that model money should be decimal under-the-hood as I have shown above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

One universal data model author I am reading contends that in his experience, 50%
I've been reading about UpdateFrom, used to update a business object from the request.
Reading on another forum I've came across the world of CSS Frameworks. The one
Reading through this question on multi-threaded javascript, I was wondering if there would be
I was reading the book Expert C# 2005 Business Objects . The book describes
I've been reading Rockford Lhotka's Expert C# 2008 Business Objects, where there is such
When reading, I keep seeing references to what they call Business Objects . I've
I was reading the Harvard Business Review (HBR) blog post , The Traits of
I'm looking for options for connecting to (primarily reading data) UNIX/AIX/Business Basic from Windows
I have been doing a lot of reading on service layers and business layers

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.