Welcome back.
In this video I wanted to show you the keyword auto implemented properties.
Because the thing is, what we did here is with this prop keyword.
For example, this here is an auto implemented property okay.
So automatically implemented.
But what I actually want to look at are read only properties.
So how can I make a property that will take care of the ID that I exposed to the outside a read only
property?
Well that is by saying there is no set.
That's it.
So suddenly this is a read only property.
That's how easy it is because it only has a getter.
So if you want to get something, you are reading it.
So you can now only read it because you cannot set it because there's no setter implemented here.
Okay, so when would you use this read only property?
Well the thing is you would use it.
If you want to make sure that you cannot override something like an ID, but you can get it.
Now, the thing is here we're not implementing yet that we actually want to get this ID, so we need
to modify it.
Do you know how to do it?
Okay, I hope you paused the video and tried it.
Basically we need to do it like so where we return the id.
Now we have implemented this getter which will return this ID here whenever we are accessing the ID
property from another class.
So why is this important?
This is important because in case of IDs, you need to have a way to identify an object by its well
by somehow something and in this case by the id, because that's the unique identifier that we are using.
Okay.
And this way we can go ahead and now access something by its ID inside of our programs file.
And now we can actually access customer.id.
Okay.
Now you see we can try to assign a value to it, but that won't work because ID is a read only property
you can see that cannot be assigned.
It is read only, but we can get the ID now.
So for example using console write line customer three ID is and then plus customer 3.id.
So now we do actually have access to the ID from the outside because we exposed it using our public
property.
Okay.
So customer three has the ID of two, customer one has the ID of zero and so forth.
That's that's because that's what our static variable here the static field takes care of.