---
title: "Struct types"
description: "Learn how Ice structs are mapped to C#"
url: https://docs.icerpc.dev/icerpc-for-ice-users/ice-definitions/struct-types
docs_index: https://docs.icerpc.dev/llms.txt
---

> For an index of every page, see [llms.txt](https://docs.icerpc.dev/llms.txt).

# Struct types

Learn how Ice structs are mapped to C#

An Ice struct maps to a partial record struct with the same name converted to Pascal case.

Consider the following Ice struct:

```ice
struct Point
{
    double x;
    double y;
}
```

The Ice compiler maps `Point` to C# as shown below:

```csharp
public partial record struct Point
{
    public double X { get; set; }
    public double Y { get; set; }

    /// <summary>Initializes a new instance of the <see cref="Point" /> struct.</summary>
    public Point(double x, double y)
    {
        this.X = x;
        this.Y = y;
    }

    /// <summary>Initializes a new instance of the <see cref="Point" /> struct from an IceDecoder.</summary>
    public Point(ref IceDecoder decoder)
    {
        this.X = decoder.DecodeDouble();
        this.Y = decoder.DecodeDouble();
    }

    /// <summary>Encodes the fields of this struct with an Ice encoder.</summary>
    public readonly void Encode(ref IceEncoder encoder)
    {
        encoder.EncodeDouble(this.X);
        encoder.EncodeDouble(this.Y);
    }
}
```

The mapped C# record struct provides a primary constructor with parameters for all its fields, and also a decoding constructor that constructs a new instance by decoding its fields from an [IceDecoder](https://code.icerpc.dev/csharp/0.7.x/api/reference/IceRpc.Ice.Codec.IceDecoder.html). The generated `Encode` method encodes the struct fields with an [IceEncoder](https://code.icerpc.dev/csharp/0.7.x/api/reference/IceRpc.Ice.Codec.IceEncoder.html).

## cs:readonly metadata directive

You can map an Ice struct to a readonly C# struct with the [`"cs:readonly"`](https://docs.zeroc.com/ice/3.8/csharp/slice-metadata-directives#SliceMetadataDirectives-cs:readonly) metadata directive. For example:

```ice
["cs:readonly"]
struct Point
{
    double x;
    double y;
}
```

```csharp
public readonly partial record struct Point
{
    public double X { get; init; }
    public double Y { get; init; }

    ...
}
```
