What is the difference between a field and a property in C#?
Hi! I started learning C# and can't fully understand the difference between a field and a property. They both seem to store data, but why do we need properties if we can just use fields? I've seen examples where people write something like:
```csharp
public class Person
{
public string Name; // field
public int Age { get; set; } // property
}
```
And they both seem to work the same way. But I've heard that properties are the "correct" way, and fields should be made private. Why? What's the catch here? Can you explain with examples? Thanks in advance!
No answers yet.
Log in to leave an answer