C # Introduction-class and object selected from "C # programming language details" and sent to the novice

Source: Internet
Author: User
Class is the most basic type in C. A class is a data structure that combines state (field) and behavior (methods and other function members) in a unit. Class provides definitions for dynamically creating class instances, that is, objects ). Classes support inheritance and polymorphism (polymorphism), that is, the mechanisms by which derived classes can expand and specialize base classes.
You can use the class declaration to create a new class. A class declaration starts with a declaration header. Its composition is as follows: first, it specifies the features and modifiers of the class, followed by the class name and the name of the base class (if any, and the name of the interface implemented by this class. The declaration header is followed by a class body, which consists of a group of member declarations contained in braces.
The following is a declaration of a simple class named Point:
Public class Point
{
Public int x, y;

Public Point (int x, int y ){
This. x = x;
This. y = y;
}
}
Create a class instance using the new operator. It allocates memory for the new instance, calls the constructor to initialize the instance, and returns a reference to the instance. The following statement creates two Point objects and saves the references of those objects to two variables:
Point p1 = new Point (0, 0 );
Point p2 = new Point (10, 20 );
When an object is no longer used, the memory occupied by the object will be automatically recycled. In C #, it is neither necessary nor possible to explicitly release the object.
1.6.1 member
Class, static member, or instance member ). Static members belong to the class, and instance members belong to the object (class instance ).
Table 1.6 provides descriptions of the various members that a class can contain.
Table 1.6 class members
Members
Description

Constant
Constant value associated with the class

Field
Class variables

Method
Computing and behavior that can be executed by class

Attribute
Enable the object to read and write the class name attributes.

Indexer
Allows objects to be indexed in the same way as arrays.

Event
Notifications that can be generated by classes

Operator
Class support conversion and expression operators

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.