C # Object-oriented

Source: Internet
Author: User

Clear structure

Good maintainability and robustness

Good extensibility

Class is the most basic unit used in the

Self-written classes-user-defined types
If the object to be produced by using a custom type must have an instantiated procedure

Instantiation format:
Type name SS = new type name ();

Access Modifier-4

Public-publicly available, accessible anywhere, but with reference to namespaces

Private-The inside of the class can only be accessed

Internal-Internal, default, assembly accessible, assembly is namespace

Protected-protected, class-Inside and class-parent classes and subclasses can be accessed

Packaging:

Private data type _ name; --Member variable/field

Public default consistent name--property

{

get{return _ name;} --Obtained by default

set{_ name = value;} --Assigned value

}

Encapsulation can protect the security of your data.

Quick Package shortcut key: Ctrl+r+e

Inherited:

A subclass has a parent class that can inherit all the public properties and methods of the parent class.

A parent class can have countless subclasses

The higher the parent, the more abstract, the lower the more specific the child.

Inherited syntax: Class Name: Parent class name (write a colon directly after the class name and the parent class name that you want to inherit)

A:b left is subclass, right is parent class

Subclass is also called XXX's derived class, Super class

The parent class is also called the base class

Polymorphic:

Subclasses have a variety of forms, can inherit from the parent class, or they can be different from the parent class

Virtual method Virtual
overriding override

The methods in the parent class are not applicable in subclasses, then the subclass needs to change the inherited methods or attributes autonomously, and the method of adding the virtual keyword to the parent class can be overridden by the subclasses.

Subclasses override the parent class by using the Override keyword

Parent class:

public class Fly    {public        virtual string Fling ()        {            return "flapping wings can fly!!!" ";        }    }

Sub-class:

   public class Plane:fly    {public        override string Fling ()        {            return "Fire can fly!!!" ";        }    }

C # Object-oriented

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.