﻿---
title: csharp_space_after_unary_operator
description: Space after unary minus/plus, logical not, and the unsafe pointer prefix operators. Not bitwise complement or prefix increment/decrement. Defaults to `false`
url: https://docs-v3-preview.elastic.dev/reference/spacing/csharp_space_after_unary_operator
---

# csharp_space_after_unary_operator
Space after unary minus/plus, logical not, and the unsafe pointer prefix operators. Not bitwise complement or prefix increment/decrement.

## Values


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

**Default:** `false`

## 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_after_unary_operator is a ReSharper generalized key (space_after_unary_operator) dotnet format does not recognise at all. Measured: dotnet format whitespace always normalises `- x`/`+ x`/`! x` back to `-x`/`+x`/`!x` regardless of any .editorconfig setting, since it has its own fixed, unconfigurable opinion here. Setting the key to true is a permanent, structural divergence from dotnet format for any file containing a unary expression — there is no shape Curb could pick that satisfies both dotnet format's fixed opinion and the key's own request at once. (`SpacingTests.Unary_minus_plus_and_not_take_a_space_when_asked`)
- **dotnet-format-whitespace**: Same permanent divergence as SpacingTests.Unary_minus_plus_and_not_take_a_space_when_asked, exercised for the two unsafe pointer prefix operators (pointer indirection `*p`, address-of `&x`) rather than unary minus/plus/not — dotnet format normalises `* p`/`& x` back to `*p`/`&x` just as unconditionally. (`SpacingTests.The_unsafe_pointer_prefix_operators_take_a_space_too`)
- **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 space back out), now confirmed under a real `dotnet build -p:EnforceCodeStyleInBuild=true` as well as the `dotnet format whitespace` CLI. (`SpacingTests.Unary_minus_plus_and_not_take_a_space_when_asked`)


### `csharp_space_after_unary_operator = true`

```ini
csharp_space_after_unary_operator = true
```

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

    public class Widget
    {
        public int Negate(int x)
        {
            int a = -x;
            bool b = !(x > 0);
            int c = ~x;
            return a + c;
        }
    }
    ```
  </tab-item>

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

    public class Widget
    {
        public int Negate(int x)
        {
            int a = - x;
            bool b = ! (x > 0);
            int c = ~x;
            return a + c;
        }
    }
    ```
  </tab-item>
</tab-set>


### `csharp_space_after_unary_operator = false`

```ini
csharp_space_after_unary_operator = false
```

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

    public class Widget
    {
        public int Negate(int x)
        {
            int a = -x;
            bool b = !(x > 0);
            int c = ~x;
            return a + c;
        }
    }
    ```
  </tab-item>

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

    public class Widget
    {
        public int Negate(int x)
        {
            int a = -x;
            bool b = !(x > 0);
            int c = ~x;
            return a + c;
        }
    }
    ```
  </tab-item>
</tab-set>