C # class

Source: Internet
Author: User

In C #, classes are "blueprints" that are abstracted and summed up from objective things.

Class members include

1. Attributes: Used to describe the characteristics of an object

2. Method: Describe the behavior of the object

3. Event: Behavior triggered under certain conditions

4, constructor: Also called the constructor, constructs the method.

Class definition uses the class keyword

Class Test

{

Members of the class

}

Field

A field is a variable defined inside a class or struct

struct POINT

{

public int x;

public int y;

}

Chass Student

{

String name;

int age;

String assress;

}

The above defines a student class containing three fields

Public access. Not subject to any restrictions.
Private access. This class is restricted to access by members, subclasses, and instances.
protected protected Access. This class and subclass access is limited, and instances cannot be accessed.
Internal internal access. Access is limited to this item and cannot be accessed by others.
protected internal internal protection access. Limited to this item or subclass access, other inaccessible

Property:

Properties are used to describe the characteristics of a class, which can encapsulate a field. Usually with get: the value and set used to get the property: The value used to set the property

in the properties can also be set, this setting is worth the condition

Add this condition so that the setting will be an error. throw new Araumentexception ("message") is used to output error messages

You can use the simplified attribute declaration syntax if the property value does not require special validation processing

Write only get; indicate that this property is read-only

C # class

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.