C # in-depth class methods

Source: Internet
Author: User

About construction

Class Student
{

Non-parametric construction

Public Student () {}

With parametric construction
Public Student (int age,string name,string ID)
{
This.age = age;
This.id = ID;
THIS.name = name;
}

This represents an instance of the current class, used to differentiate the entry and member variables

}

For construction, you can construct a function in a class

1. The method name is the same as the class name

2. No return value type

3. Main completion of the initialization method between objects

Method overloading

If more than one method in a class has the same method name, the parameter list is different, which is the method overload. Independent of return value type

Constituent method overloads

1. Different types

2. Different order of variables

3. Different number of parameters

Class 1:

Public void Play (Music music)
{

}
public void Play (Sprict sprict)
{

}
public void Play (song song)
{

}

Class 2:

Student stu = new Student ();
Stu.play (New Music ());
Stu.play (New Sprict ());
Stu.play (New Song ());

Method overloading!!!

One of the constructs is also a method overload

Interaction between objects

Cond.....................................................................................

C # in-depth class methods

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.