Class, component, namespace --

Source: Internet
Author: User

How do you understand the class and object orientation.

Class 1 Introduction

1) Why use oop? (Object-Oriented Programming) oop has three features: encapsulation, inheritance, and polymorphism.

2) method in 3 of Instantiation

Text mytext = new text () New generates an object. The object variable mytext is only a reference to the object ,... The object is saved in the heap, and the object variable exists in the stack (the address of the object inside the heap ),

Filestream FS = file. Create ("data. Indium") -- (for constructors that are not accessible, the create method returns a reference to the class instance)

Use reflection (reflection)

3) Static members,

A static member does not belong to any object. 1. It can be accessed directly by class name. 2. An instance Member must create an object reference for access.

The start of a constant is an implicit static state, and can be directly accessed by the class name.

Public const double Pi = 3.1415;

Public static int p = 0;

Conclusion: The instance field is related to an instance of the class. each instance of the class has its own copy of the Instance field, and the static field is related to the class itself, it is not related to the instance. No matter how many class instances you create, the static field has only one copy.

When to use static, when we need global data and code (the code is public ), the static keyword after C #2.0 can also be used to modify the class (when any member of the class is static)

3. namespace

Namespaces can be divided by logic. 1 enhances readability and 2 reduces class name conflicts.

2) Hierarchical namespace (namespace can also contain other namespaces)

Namespace teamx

{

Namespace business

{

Pubclic Class {}

}

}

4 components,

Component: in our own words, many components are put together with classes.. NET is also called assembly. The component is related to the physical location of the storage and has no direct relationship with the namespace.

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.