Again to summarize the knowledge of the time, today in the cloud and college continue to learn some of the use of inheritance, and the use of collections. Let's summarize it down here.
Theory:
the constructor for calling the parent class is displayed, the keyword: base, the constructor cannot be inherited, and the subclass object is instantiated to invoke the constructor of the parent class first. If the subclass is the same as the method name of the parent class, then our object will call the object of the child class.
Conversion of parent class and subclass
Person p = new Teacher (); subclasses can be implicitly converted to a parent class. the conversion is premised on the fact that the transformed class does have an inherited relationship.
access Modifiers
Private: A privately owned member that can be accessed within a class.
The default access modifier for fields and methods in a class is private
Public: Common members, completely public, without access restrictions.
Internal: Can be accessed in the current assembly.
Protected: Protected members, which are accessible within the class and inherited classes, and do not allow other non-subclass access
ArrayList Collection
You can see the set as "variable length, with many methods of array
The data can be accessed through subscript only if the item is found
ArrayList elements are added, inserted, deleted, emptied, sorted, reversed.
The length of the collection is represented by a Const .
• referencing the System.Collection namespace
• Manually add (you must remember the namespace)• The cursor stops in the code, the shortcut key or the right mouse button (must remember the class name)
The learning set can be summed up in the available methods
Add Data : Add (), AddRange ()---adding array• Using Add to add data, and as an array, you can use the Subscript (index) to access the data• Data accessed using subscript is of type object and must be converted if necessary to meet the Richter conversion principle• Why do you want to set the add parameter to object? For UniversalAddRange Adds a batch of data from an array or collection . • How many data are in the array or collection, how many data are added in the new collection, and the type one by one corresponds • But add can also join an array or collection as data, but add the array or collection as an item in the past
Insert Data : Insert ()Use Syntax: Collection name. Insert (position, value); Position determination, using the inserted data to count the second data is the content of the data to be inserted
Delete Data : Remove (), RemoveAt (), Clear ()
Remove Methodarraylist.remove (data)• Delete data that is the same as "data" in the collection• When this data does not exist in the collection, directly ignore the• Method execution Deletes the first occurrence of data from left to right, after which the data is not considered
RemoveAt Method• Delete the data from the specified index, and the data is then moved forward sequentially• When the index is out of range, the exception
Clear ()Determine if it contains:
Contains () sort can handle sorting functions (even Max, Min, AVG, etc.)
Next ()• Generates a random number within an integer range, Next (num)
Hashtable Method•Hashtable, deletion, investigation and deposit. • Add data, all in the form of "key-value pairs"• Key-value pairs are object types• Keys in key-value pairs are used to find data, must be provided, not allowed to repeatHashtable using keys as a way to look for, is an unordered structure• Get Data• Using the • Strong turn, use the Richter conversion principle
Generic Collection•generic collections are designed to handle a particular type of
ArrayList corresponds to list< type name >
• What types are written in angle brackets, and what type of collection does this set become?• Add data, insert data, index Access data is of this type, regardless of all conversion issues
Real :
the application of ArrayList collection
HashTable application
Application of generic Collection
Well, because I'm not too clear about the transformation of the parent class and the subclass, I'm sorry I couldn't summarize it today. By tomorrow I'll figure it out and fill it up with what I left behind today. Come on!
C # inheritance, collection (Eleventh day)