In C# 3.0 and later, auto-implemented properties make property-declaration more concise when no additional logic is required in the property accessors. They also enable client code to create objects. When you declare a property as shown in the following example, the compiler creates a private, anonymous backing field can only be accessed through the property’s get and set accessors.
// Auto-Implemented Property for trivial get and set
public double TotalPurchases { get; set; }
Equivalent to:
// Auto-Implemented Property for trivial get and set
private double _totalPurchases;
public double TotalPurchases
{
get { return _totalPurchases; }
set { _totalPurchases = value; }
}
As you can see the above, it is a nice syntactic sugar which allows you to write shorter code.
Did you find this article useful? If you have any feedback or questions, please let me know in the comments below.
Thank you for reading and happy coding!
5. Actions for Organizations (Tenants)
In our previous post, we introduced a Razor Page tailored for tenants, featuring three essential action buttons: Add, Edit and Delete. In this post, we'll delve into the implementation of these buttons' functionalities.
6. Persisting with Entity Framework Core
In a previous post, we learned how to implement functionality for the Add, Edit, and Delete actions. However, it's important to note that any changes made will be lost once the project is no longer running, as we are using a static variable, OrganizationsData, which is not persisted.