In the previous article, we introduced C # as a fully object-oriented language. Since it is a fully object-oriented language, we should use the object-oriented model to learn C #, do not know about object orientation? Don't worry. This article will introduce the Object-Oriented Knowledge Used in the basic part of C #. Later, we will introduce C # Object-Oriented Programming systematically. Next we will start the C # Journey!
Class 1 and Object
1. What is a class?
In our real world, we often classify things with the same behaviors and attributes. For example, humans are what we call classes.
For example, all people have five senses, guts, and so on (except for other special reasons). These components are called human attributes.
All people need to eat, sleep, and so on (except for other reasons such as losing weight). These actions are called behavior.
2. What is an object?
We just learned what is the behavior and attribute of the Class and Class, so the object is an object of this class!
A class is the description of a group of behaviors and attributes. An object is an object that meets these descriptions.
Class: class is the description and abstraction of a series of identical behaviors and attributes.
Object: an object is an object of A Class. It is an instance of its existence. Then, a human object can eat, sleep, and has facial features and insides.
Class 2 members
After learning the basic concepts of classes and objects, let's look at a piece of code:
1 Using System;
2
3 Namespace MyHelloWorld
4 {
5 Class Student
6 {
7 Public String _ Name;
8 Public Int _ Age;
9 }
10
11 Class Program
12 {
13 Static Void Main ( String [] Args)
14 {
15 Student std = New Student (); // Create a Student Class Object
16 Std. _ name = " Zhang San " ; // Assign a value to the name attribute of the student object
17 Std. _ age = 20 ; // Assign a value to the age attribute of the student object
18
19 // Print the name and age of the student object std
20 Console. WriteLine ( " My name is: " + Std. _ name );
21 Console. WriteLine ( " My age is: " + Std. _ age );
22 }
23 }
24 }
First, see 5th ~ The nine lines of code demonstrate the syntax for C # To create classes and attributes (representing the C # field, which is understood as the attributes in the object-oriented model. When the C # attribute is described, I will correct it:
Class Student
{