A property is a special way to access and modify data in a class.
Instead of directly accessing variables, properties allow controlled access using get and set.
Properties help protect data and make your code more flexible.
Here is a simple class using properties.
A field is a simple variable, while a property adds control over how the value is accessed.
You can customize the behavior of properties using get and set.
This allows you to add logic like validation or formatting.
A property can be read-only by removing the set.
This means the value can only be accessed, not changed.
A property can also be write-only by removing the get.
This is less common but useful for sensitive data.
Properties are a core part of C# development and are used in almost every real-world application.
Create a Student class with Name and Age properties. Add validation so Age cannot be negative.