C # Series II "C # preliminary exploration and objects"

Source: Internet
Author: User

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;

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
{
Related Article

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.