C # inheritance, set (Eleventh day ),

Source: Internet
Author: User

C # inheritance, set (Eleventh day ),

It was time to sum up the knowledge. Today, I continue to learn some application of inheritance and collective application in cloud and college. Let's summarize it.

Theory:

Displays the constructor that calls the parent class. The key word is base. The constructor cannot be inherited. When the subclass object is instantiated, the constructor of the parent class is called. If the method name of the subclass is the same as that of the parent class, our object will call the subclass object.

 

Conversion of parent and child classes

Person p = new Teacher (); subclass can be implicitly converted to the parent class. The premise of conversion is that the converted class does have an inheritance relationship. Access Modifier

Private: a private member that can be accessed within the class.

The default access modifier for fields and methods in the class is private.

Public: A public member. It is completely public and has no access restrictions.

Internal: accessible within the current Assembly.

Protected: protects members, which can be accessed within and from inheritance classes. Other non-subclass access is not allowed.

ArrayList set

The set can be viewed as an array with Variable Length and many methods.

Only when this item is found can the data in it be accessed through the subscript

Add, insert, delete, clear, sort, and reverse an ArrayList element.

Set lengthConst.

• Reference the System. Collection namespace

• Manually add (The namespace must be remembered) • Place the cursor in the code, shortcut key or right-click (the class name must be remembered) You can summarize the available methods in the Learning set. Add data: Add (), AddRange () --- add an array use Add • Use Add to add data, and use "subscript" (INDEX) like an array) access Data • data accessed by subscript is of the object type and needs to be converted if necessary. The conversion principle must be met. • why should we set the Add parameter to object? For general purpose • AddRange, add data in an array or set one by one in batches • How many data exists in an array or set, and how many data is added to the new set, type, etc. • but Add can also Add an array or set as data, but Add the array or set as an item to Add the past Insert data: Insert () use the Syntax: Set Name. Insert (location, value); // determine the position, use the inserted data to count the second data is the data to be inserted. Delete data: Remove (), RemoveAt (), Clear () Remove Method• ArrayList. remove (data) • delete data from a collection that is the same as "data" • when this data does not exist in the collection, ignore directly • The method is executed to delete the first data that appears from left to right. The subsequent data is not considered. RemoveAt Method• Delete the data from the specified index, and then move the data forward in sequence • when the index is out of range, an exception occurs. Clear ()Determine whether it contains: Contains ()Sort and other sorting functions (even Max, Min, AVG, etc) Next ()• Generate a random number in the Integer Range, Next (num) HashTable Method• Add, delete, query, and save HashTable. • Add data in the form of "key-value pairs" • Key-value pairs are of the object type • keys in the key-value pairs are used to find data and must be provided, repeat is not allowed • Hashtable uses the key as the search method, is a disordered structure • get data • Use the Generic set• Generic collections are designed to specifically process certain types.

• ArrayList corresponds to List <type Name>

• What type is written in angle brackets, and the Set Becomes a set of the type • add data, insert data, and index access data are all of this type, so you don't have to consider all the conversion issues. Practice: Application of ArrayList set

 HashTableApplication

Application of generic Sets

Well, because the conversion between the parent class and the Child class is not very clear, I am sorry that I cannot summarize it today. By tomorrow I will figure it out, and then I will make up what is left over by today. Come on!

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.