Chapter One overview of collections classes, generic classes, and timing classes

Source: Internet
Author: User

1.1 Definition of Cluster (collection)

A cluster is a structured data type. Store data and provide data additions, deletions, and changes, as well as setting and returning operations for different attribute values of the cluster.

Clusters are divided into two categories: linear and nonlinear clusters.

A linear cluster is a list of elements in which the elements in the table are connected sequentially. (1, 2, 3, 4) the array in the computer world is a linear cluster.

Non-linear clusters contain elements that do not have a positional order within the cluster. (2,3,6,1) in the computer World, trees, heaps, graphs, and sets are non-linear clusters.

1.2 Description of the cluster (collection)

There are several subcategories in the two main cluster classes. A linear cluster may be either a direct access cluster or a sequential access cluster. A linear cluster can be either a hierarchical cluster or a group cluster.

1.2.1 Direct access cluster (collection)

The most common example of a direct access cluster is an array. This defines the array as an element cluster with the same data type, and all array elements can be accessed directly through the index (item[0], item[1], item[2])

An array can be static so that when an array is declared it is easy to fix the number of specified elements for the length of the program. Arrays can also be dynamic, and the number of array elements can be increased by ReDim or ReDim Preserve statements. (Note that this method applies to vb,c#, use array.resize (obj,n))

In the C # language, an array is not just a built-in data type, it is also a class.

We can store a linear cluster with an array class. Adding a new element to an array is easy, just make it simple. The new element is placed at the end of the array. However, inserting an element in an array is less efficient. Because you want to empty the inserted elements, you must move the array elements sequentially. It is also efficient to delete an element from the end of an array, but deleting an element of the specified location is less efficient.

A string is another type of direct access to a cluster. A string is a cluster of characters. As well as accessing array elements, it can be accessed based on the index of the string. In the C # language, strings are also implemented as class objects. This class contains a large collection of methods that perform standard operations on strings, where operations are concatenated, return substrings, insert characters, remove characters, and so on.

C # strings are immutable. means that once the initialization is not changed. When you want to modify a string, instead of changing the original string, create a copy of the string. In some cases this behavior can lead to a dramatic decrease in performance, so. The NET Framework provides the StringBuilder class for users to handle mutable strings.

Structs (also known as records in other programming languages) are the last type of direct access cluster. A structure is a composite data type. The data it contains may have many different data types. Because it is easy to confuse the values of these data in separate variables, the programming language uses structures to store such data.

The strength of the C # language's architecture is to define methods for performing operations stored on the data. Although it is not possible to inherit from a struct or derive a new type, this practice makes the structure much like a class in some places.

usingSystem; Public structName {Private stringfname, Mname, lname;  PublicName (stringFirststringMiddle,stringLast ) {fname=First ; Mname=Middle; LName=Last ; }       Public stringFirstName {Get{returnfname;} Set{fname =FirstName;} }       Public stringMiddleName {Get{returnMname;} Set{Mname =MiddleName;} }       Public stringLastName {Get{returnlname;} Set{lname =LastName;} }       Public Override stringToString () {return(String.Format ("{0} {1} {2}", fname, Mname,lname)); }       Public stringinitials () {return(String.Format ("{0}{1}{2}", fname. Substring (0,1), Mname. Substring (0,1), lname. Substring (0,1))); } }  Public classNametest {Static voidMain () {Name myName=NewName ("Michael","Mason","McMillan"); stringFullName, Inits; FullName=myname.tostring (); Inits=myname.initials (); Console.WriteLine ("My name is {0}.", FullName); Console.WriteLine ("My initials is {0}.", inits); } }  
View Code

Chapter One overview of collections classes, generic classes, and timing classes

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.