Browse
Sample.LibCore.DataMoney
.md
struct

Money

publicreadonly
namespace Core.Data; public readonly struct Money : IEquatable<Money>

An immutable amount of money in a specific currency.

Arithmetic is only defined for amounts in the same currency.

  • Amounts are rounded to 2 decimal places.
  • Currency codes follow ISO 4217.

Constructors

#public Money(decimal amount, string currency = "EUR")

Creates a new amount.

amountThe amount.

currencyThe ISO 4217 currency code, e.g. "EUR".

Fields

#public static readonly Money Zero;

A zero amount in euros.

Properties

#public decimal Amount { get; }

Gets the amount.

#public string Currency { get; init; }

Gets the ISO 4217 currency code.

Methods

#public bool Equals(Money other)

Indicates whether the current object is equal to another object of the same type.

otherAn object to compare with this object.

returnstrue if the current object is equal to the other parameter; otherwise, false.

#public override bool Equals(object? obj)

Indicates whether this instance and a specified object are equal.

objThe object to compare with the current instance.

returnstrue if obj and this instance are the same type and represent the same value; otherwise, false.

#public override int GetHashCode()

Returns the hash code for this instance.

returnsA 32-bit signed integer that is the hash code for this instance.

Operators

#public static Money operator +(Money left, Money right)

Adds two amounts.

leftThe first amount.

rightThe second amount.

returnsThe sum of left and right.

throws InvalidOperationException: The currencies differ.

#public static implicit operator Money(decimal amount)

Converts a decimal to an amount in euros.

amountThe amount.