Lesson 14 Education Properties in Class #C

This is our lesson no 14 Education Properties in Class #C. Properties (in # c) allow you to regulate how a class’s variables are accessed and changed. Methods or functions outside the current class are in the oriented Object Oriented Oriented Object language, which is the suggested way and right for accessing a class’s variables.

Education Properties in Class #C

When another function or class in the programme wishes to access a variable of a class, rather than utilising the variable directly, they should access it through a property or property variable in their class.

Work with classes (for the first time, how to use a property or property we offered) using the teacher’s examples from the previous session.

A property or property is similar to a variable variable and a method method combined.

Property Although the parametric cannot be obtained, the amount can be changed by using its means before sending and receiving the variable. Let Each property or property is made up of two parts: Get and SET, as seen in the example below.

Property set are defined:

private string color;
 public string Color
 {
 get { return color; }
 set { color = value; }
38
 }

The GET method reads the variable value and returns it to the program, on the other hand, the SET method also has the desired amount to Attributes the variable. The first example is the simplest defining mode of property in #c, but can extend it
Give also.

Important: Important issue when defining a property or property is to define one of the SET methods or
GET is also sufficient and, if defined one, the definition of another method is optional.

This issue is the possibility of definition Properties only read-read or just write ONLY-WRITE.

In the following code, we have shown a more complete example of how to define the properties in #C:

public string Color
 {
 get
 {
 return color.ToUpper();
 }
 set
 {
 if (value == "Red")
 color = value;
 else
 Console.WriteLine("This car can only be red!");
 }
 }

In the above example code, we expanded the property slightly. In the new code, the Color variable when returned, because The use of the () Tupper method is returned in upper case.

On the other hand, using the command Conditional IF, only the color value of the “RED” for the COLOR variable is accepted.

%d bloggers like this: