C #-class

Source: Internet
Author: User
1. attributes and constructors Class Computer
{
Private   String Name;
Public   String Name
{
Get
{
Return Name;
}
Set
{
Name = Value;
}
}

Public   String Motherboard =   " AA SA " ;
Public Computer ( String Name)
{
This . Name = Name;
}
}


2. Inheritance
C # only supports single inheritance, but can inherit multiple interfaces

2.1 single inheritance ClassA
{
Public StringName {Get;Set;}
}

ClassB:
{

}

More than 2.2 inheritance, ClassA
{
Public StringName {Get;Set;}
}

InterfaceInterfacea
{
VoidMethoda ();
}

class B: A, interfacea
{< br> Public void methoda () {
///
}< br>
}

2.3 InterfaceInterfaceb
{
VoidMethodb ();
}

Class C: A, interfacea, interfaceb
{
Public   Void Methoda ()
{
//
}
Public   Void Methodb ()
{
//
}
}

3. Class Modification
Public class classname {}
Public static class classname {}
Public sealed class classname {} cannot be inherited
The public partial class classname {} Local type allows us to divide a class, structure, or interface into several parts, which are implemented in several different. in the CS file, the local types of each part are still merged into a complete class during compilation. The modifier partial must exist before each class of the same type.
Restrictions on local partial
(1) local types are only applicable to classes, interfaces, and structures. Delegation and enumeration are not supported.
(2) Each part of the same type must have a modifier partial.
(3) When using a local type, each part of a type must be in the same namespace.
(4) Each part of a type must be compiled at the same time.

From: http://www.cnblogs.com/beniao/archive/2008/07/26/1249030.html

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.