C#C
C#3y ago
lukkasz323

❔ Are these properties the same? `{ get => x; }` vs `{ get; } = x;`

I would like to know if these have any other differences besides the syntax.

Case 1:
public int TileSize { get; } = 64;

Case 2:
public int TileSize { get => 64; }


In my code below I have other properties that use the 2nd case, but that's because of more specific reasons, for example:

public (int x, int y) Center 

    {

        get => (_terrain.GetLength(1) / 2, _terrain.GetLength(0) / 2);

    }

I'm not sure which one would be better in the long run (if there are no other differences).

Previously I always used the 1st case, but here 2nd case seems more consistent with properties below, so this leaves a little confused as I never even thought about the 2nd case.
Was this page helpful?