Thank you in advance I am quite new to coding so please be patient. Below is a piece of code on which I am working. This is the complete code below it is as follows:
using the system; Public class product {name of private string; Private decimal value; Public string name {get {return name; } Set {name = value; }} Public decimal value {received {return value; } Set {value = value; }} Public product (string name, decimal value) {this.name = name; this. Value = value; }}
In the page load method, an object is immediately assigned and the constructor is said to be as follows:
Private zero page_load (object sender, EventArgs e) {Product Sale Product = New Product ("Kitchen Garbage", 49.99 M); }
When the product is created, the constructor is started with the above values. Now if you look in the constructor, then you have:
this.name = name;
and
this.price = value;
After executing the above two lines of code, property accessors automatically provide private variables ("name" and "value") with prices.
How are the lines:
this.name = name;
and
this.price = value;
Able to call public accessers named "name" and "price"?
I have only seen when a public accessor is explicitly called like:
sales product. Name = "kitchen trash";
I do not understand how:
this.name = name;
and
this.price = value;
I can directly reach a personal variable I thought the whole thing about property accessories was that you will have to go through the property name to use the private variables:
saleProduct.Name = "kitchen trash";
Can you help and explain it?
this.name = name;
and
this.price = value;
Able to reach public properties? Even the name of the property i.e. "name" and "value" is changed to "kitchen trash" and "49.99" respectively, when the above two lines of code are executed.
In addition, how to
this.name = name;
and
this.price = value;
Know what public caller is to call?
Thank you.
"text">
private member names
and Values are available in all non-static methods within the
class product
. Since for the product
the constructor is part of the class, the members can also be there.
Your constructor is not using public properties names
and value
. They get their values from the respective private members.
No comments:
Post a Comment