C#.net's Eighth day study

Source: Internet
Author: User

1. Process-oriented-----> Object oriented

Process oriented: It is the process of accomplishing this thing, emphasizing the action of accomplishing it.

Put the elephant in the freezer
1. Open the refrigerator door
2. Tuck in the Elephant and kiss the elephant's butt.
3. Close the refrigerator door

Zhang San skinny little Dick Silk
Zhang San on the small bench to open the refrigerator door
Zhang San find John Doe help put the elephant into the refrigerator, Zhang San stepping on the bench to kiss.
Zhang San on the bench to close the refrigerator door

John Doe 190cm very strong
1, Lee can open the refrigerator door himself
2, Li himself stuffed the elephant into the refrigerator, Lee can kiss his own.
3, Li himself closed the refrigerator door

If we use process-oriented thinking to solve this matter, when the people who do it are different,
We need to tailor a solution to each individual.

Object oriented: Find an object to help you do something.
Put the elephant in the freezer
We use refrigerators as objects:
1, the refrigerator door can be opened
2. Elephants can be stuffed into refrigerators.
3, the refrigerator door can be closed

Object-oriented: intended to write a generic code that masks differences.

Close the door
Process-oriented: closing
Zhang San kicked the door tight.
John Doe the door lightly.
Harry door is not closed, left a tail

Object-oriented: closing
The door can be closed

I drew a few scraps on the blackboard.
Use Circles as objects
The circle can be drawn on the blackboard

Use the blackboard as an object
The blackboard can be drawn round

I drew a circle on the blackboard.
Zhang San came up with a ruler that drew a special round circle.
John Doe come up with a random scratched
Harry up the compass drew a circle
The circle can be drawn on the blackboard
The circle can be drawn on the blackboard
Use a circle as an object: The circle can be drawn on the blackboard.
The blackboard can be drawn round
Blackboard as an object: can be drawn by the circle is drawn the square is drawn the positive direction

Try to describe the characteristics and behavior of Zhang San and John Doe.
Name: Zhang San
Gender: Male
Height: 180cm
Weight: 70kg
Age: 22 years old
Eating and drinking, sleeping, all normal and healthy.
Eat and drink, gamble and smoke

Name: John Doe
Gender: Male
Height: 180cm
Weight: 70KG
Age: 23 years old
Brain residue, all health.

We describe an object in code by describing the properties and methods of the object
The object must be visible and palpable.

Lights: Properties and methods
Property:
Shape: Long
Brightness: 500W
Color: White
Brand: XX
Method: Glow

Fans: Properties, methods
Form factor: Three blades
Color: White
Brand: XX
Method: Rotate, fan

We further encapsulate these objects with the same properties and methods, abstracting out the concept of class.
A class is a mold that determines the properties and methods that an object should have.
Objects are created from classes.
The class is a building drawing object that is built up.

2. Class
Grammar:
[Public] class name
{
Field
Properties
Method
}
After writing a class, we need to create the object of this class,
So, the process of creating an object for this class is called instantiation of the class.
Use the keyword new.

This: Represents the object of the current class.
The class is not in memory, and the object is memory-occupied.

3. Properties
The function of a property is to protect a field, assign a field, and qualify a value.
The nature of the property is two methods, one called Get () and one called set ().
Both get () and set () are the readable writable properties.
Only get () does not have set () What we call a read-only property
No get () only set () What we call a write-only property

Field fields
Method methods
Property Properties

A field is a woman's property is a man.

4. Access modifiers
Public: Publicly available, accessible anywhere.
Private: It can only be accessed within the current class, and this class is inaccessible.

5. Once we have created an object of a class, we need to assign a value to each property of the object.
We call this process the initialization of the object.

6. Static and non-static differences
1), in a non-static class, there can be either an instance member or a static member.
2), when invoking instance members, you need to use the object name. Instance members;
When you call a static member, you need to use the class name. static member name;
Summary: Static members must be called using the class name, and instance members are invoked using the object name.
In a static function, only static members can be accessed and instance members are not allowed.
Instance functions, you can use either static members or instance members.
Only static members are allowed in static classes, and instance members are not allowed.

Use:
1), if you want your class to be used as a "tool class", consider writing the class as static.
2), static classes in the entire project resource sharing.
A static class frees resources only after the program has all finished.

Stack static storage area

Frees resources. GC Garbage Collection Garbage collector

7. Constructor function
Role: Helps us initialize the object (assigning values to each property of the object in turn)
A constructor is a special method:
1), the constructor does not return a value, and even void can not be written.
2), the name of the constructor must be the same as the class name.

Constructors are executed when an object is created
Constructors can have overloads.
***
There is a default parameterless constructor in the class, and when you write a new constructor, whether it is a parameter or
Without parameters, the default parameterless constructor is eliminated.
8. New keyword
Person Zsperson=new person ();
New has helped us do 3 things:
1), open a space in memory
2), create objects in the open space
3), invoking the object's constructor to initialize the object

9. This keyword
1), object representing the current class
2), the constructor for calling this class, shown in the class: this

C#.net's Eighth day study

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.