c#-Classes and objects

Source: Internet
Author: User

VS Classes and objects
    • Static members, static methods
belongs to the class, not to the object, and is called directly by the class instance member to the class itself, that is, the class object itself. Static members belong to all objects, that is, all objects are available. static string Astringstatic getastringlength () {}
    • Domain
belongs to the class member generally is private, if is private, the class outside generally uses the domain accesses the string bsring; The constant field. Default static, you must use the initial value setting. const int Anum=1; read-only domain. If it is static, it must be declared with an initial value, and normal must be assigned in the build function. ReadOnly string astring;
    • Object contains objects
You can set the field to represent the object and implement the object containing the object. The name of the. Domain name (or attribute name). The name of the containing object. When used, it is necessary to generate the object and the contained object, and then assign the memory address of the contained object to the field of the outer object. Another object that contains another object is that the class contains another class, that is, nested classes, which do so when outside the inner class, using???.
    • Property
Domain wrapper, the property gets changed by the domain, the property itself is not saved, saved with the domain. Fields and methods are members of the class private string astring;    Yasring implicitly has the value parameter {get {return astring;    } set {asring =value; }}myclass. yasring = "1"; implicitly invokes the property to assign a value to the private domain
    • Method
belongs to a class member
    • Function Method overloading
The function method names are the same, the parameters are different, the parameter types are different, the return values can be different.
    • Build function
The build function, with the same name as the class, invokes the creation object when creating the object MyClass MyObject = new MyClass (); MyClass () Creates an object, new allocates a memory address, = Saves the new object's measured address to MyObject, MyClass declares the MyObject variable, that is, MyObject holds the memory address of the new object can be =null, cancels the object's reference.
    • destructor,
~ Add class Name
    • Name space
Used to differentiate between classes of the same name, nested namespaces, which are many-to {} or namespaces. namespaces. Namespaces
    • Access restrictions
Public protect available in private class interval class, inside program, derived class available Intereval class, protect class available inside program, derived class available
    • Parameter Passing value
The variable value of the calling method is not changed, and the parameter value of the method is copied.
    • Parameter Passing Reference
The variable that invokes the method can be changed within the method. A reference to a variable is passed, that is, the memory address is preceded by a ref, and the method is also ref
    • Parameter return value
The call statement is added out, the method is also added out, when the need to return multiple values of the method is useful, because the return value of the method is only one.
    • Hide
A variable with the same name as the class can be declared within a method, and within a method, the variable defaults to the variable declared by the method, hiding the variable of the class to which the method belongs. In a method that hides a variable, you need to use the this. Variable name, which represents the current object, when a variable of the class being hidden is needed.
    • Life cycle
Determines whether the variable has an address in memory during the life cycle. object is not created, it is not in the life cycle, there is no memory address. If the variable is no longer being used, the memory address that is taken up is automatically reclaimed by the garbage collection mechanism.
    • Default value
int 0 Character type/0 (character) string Nullbool false object default value NULL

c#-Classes and objects

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.