﻿---
title: csharp_space_around_ternary_operator
description: Space around the ?/: of a ternary conditional expression. Defaults to `true`
url: https://docs-v3-preview.elastic.dev/reference/spacing/csharp_space_around_ternary_operator
---

# csharp_space_around_ternary_operator
Space around the ?/: of a ternary conditional expression.

## Values


| Value   | Notes |
|---------|-------|
| `true`  |       |
| `false` |       |

**Default:** `true`

## Conformance

Curb's output is not always a fixed point of the tool(s) below for this key — see [conformance divergences](https://docs-v3-preview.elastic.dev/design-principles/conformance-divergences) for the full registry.
- **dotnet-format-whitespace**: csharp_space_around_ternary_operator is a ReSharper generalized key (space_around_ternary_operator) dotnet format does not recognise at all. Measured: dotnet format whitespace always normalises `x > 0?x:0` back to `x > 0 ? x : 0` regardless of any .editorconfig setting — spacing around a ternary's ?/: is not configurable there. Setting the key to false is a permanent, structural divergence from dotnet format for any file containing a ternary expression. (`SpacingTests.The_ternary_operator_can_lose_its_surrounding_space`)
- **dotnet-format-whitespace**: Same permanent divergence as SpacingTests.The_ternary_operator_can_lose_its_surrounding_space, exercised on a ternary long enough to wrap under max_line_length — the wrap point itself (a SoftLine) is unaffected by the option, only the flat spacing dotnet format keeps re-adding is. (`SpacingTests.A_wrapped_ternary_still_breaks_without_the_space`)
- **ide0055**: Same permanent divergence as the dotnet-format-whitespace entry above (a ReSharper-only key dotnet format has no concept of, so it always normalises the spacing back), now confirmed under a real `dotnet build -p:EnforceCodeStyleInBuild=true` as well as the `dotnet format whitespace` CLI. (`SpacingTests.The_ternary_operator_can_lose_its_surrounding_space`)
- **ide0055**: Same permanent divergence as SpacingTests.The_ternary_operator_can_lose_its_surrounding_space above, exercised on a wrapped ternary, now confirmed under a real `dotnet build -p:EnforceCodeStyleInBuild=true` as well as the `dotnet format whitespace` CLI. (`SpacingTests.A_wrapped_ternary_still_breaks_without_the_space`)


### `csharp_space_around_ternary_operator = true`

```ini
csharp_space_around_ternary_operator = true
```

<tab-set>
  <tab-item title="Before">
    ```csharp
    namespace N;

    public class Widget
    {
        public int Clamp(int x)
        {
            return x > 0 ? x : 0;
        }
    }
    ```
  </tab-item>

  <tab-item title="After">
    ```csharp
    namespace N;

    public class Widget
    {
        public int Clamp(int x)
        {
            return x > 0 ? x : 0;
        }
    }
    ```
  </tab-item>
</tab-set>


### `csharp_space_around_ternary_operator = false`

```ini
csharp_space_around_ternary_operator = false
```

<tab-set>
  <tab-item title="Before">
    ```csharp
    namespace N;

    public class Widget
    {
        public int Clamp(int x)
        {
            return x > 0 ? x : 0;
        }
    }
    ```
  </tab-item>

  <tab-item title="After">
    ```csharp
    namespace N;

    public class Widget
    {
        public int Clamp(int x)
        {
            return x > 0?x:0;
        }
    }
    ```
  </tab-item>
</tab-set>