# Money

`struct` `public` `readonly`

```csharp
namespace Core.Data;

public readonly struct Money : IEquatable<Money>
```

An immutable amount of money in a specific currency.

> **Remarks**: Arithmetic is only defined for amounts in the same currency.
>
> * Amounts are rounded to 2 decimal places.
> * Currency codes follow ISO 4217.

## Constructors

{% member id="ctor" %}
```csharp
public Money(decimal amount, string currency = "EUR")
```

Creates a new amount.

* **amount**: The amount.
* **currency**: The ISO 4217 currency code, e.g. `"EUR"`.

{% /member %}

## Fields

{% member id="zero" %}
```csharp
public static readonly Money Zero;
```

A zero amount in euros.

{% /member %}

## Properties

{% member id="amount" %}
```csharp
public decimal Amount { get; }
```

Gets the amount.

{% /member %}

{% member id="currency" %}
```csharp
public string Currency { get; init; }
```

Gets the ISO 4217 currency code.

{% /member %}

## Methods

{% member id="equals" %}
```csharp
public bool Equals(Money other)
```

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

* **other**: An object to compare with this object.

**Returns**: `true` if the current object is equal to the `other` parameter; otherwise, `false`.

{% /member %}

{% member id="equals-2" %}
```csharp
public override bool Equals(object? obj)
```

Indicates whether this instance and a specified object are equal.

* **obj**: The object to compare with the current instance.

**Returns**: `true` if `obj` and this instance are the same type and represent the same value; otherwise, `false`.

{% /member %}

{% member id="gethashcode" %}
```csharp
public override int GetHashCode()
```

Returns the hash code for this instance.

**Returns**: A 32-bit signed integer that is the hash code for this instance.

{% /member %}

## Operators

{% member id="op-addition" %}
```csharp
public static Money operator +(Money left, Money right)
```

Adds two amounts.

* **left**: The first amount.
* **right**: The second amount.

**Returns**: The sum of `left` and `right`.

**Throws** `InvalidOperationException`: The currencies differ.

{% /member %}

{% member id="op-implicit" %}
```csharp
public static implicit operator Money(decimal amount)
```

Converts a decimal to an amount in euros.

* **amount**: The amount.

{% /member %}
