0

What is the difference between the => operator for properties and auto property in C#?

I have properties like

public string Name => name;

but Resharper suggests that I convert them to auto properties instead:

public string Name { get; }

I do not see any added value from this. Is there any difference between the two?

andreas
  • 157
  • 13

1 Answers1

2

The difference is that the auto property creates the backing field automatically. If you don't need it, the auto property is probably more convenient.

adjan
  • 13,371
  • 2
  • 31
  • 48
  • 1
    An auto-implemented property does create a backing field, but you can't use it in your code, it's not accessible to you. – Zohar Peled Apr 30 '18 at 14:55