How is the array in C #. NET implemented?

Source: Internet
Author: User

How is the array in C #. NET implemented?

This article discusses how to convert a List into an Array.

Should we use arrays or linked lists in C? Array or generic List <T>.

Problem:

(1) the array of C # can be converted by List. When the List length is very large, it requires a lot of memory. We believe that the array is not a whole block of memory. Therefore, arrays must be composed of multiple memories. Naturally, arrays are composed of linked lists and arrays.

(2) How long does it take to convert a List to an array?

(3) What is an Array composed?

Refer to the introduction of MSDN:

Let's take a look at msdn's definition of Arrays:

(1) in C #, arrays are actually objects, not just addressable contiguous memory areas like in C and C ++. Array is the abstract base type of all Array types. You can use attributes of Array and other class members. In this example, the Length attribute is used to obtain the Length of an array.

(2) The Array type is a reference type derived from the abstract base type Array. Because this type implements IEnumerable and IEnumerable, you can use foreach Iteration for all arrays in C.

An Array is a reference type derived from an Array.

(3) Let's look at the introduction to Array.

The Array class is a base class that supports the implementation of the Array language. However, only the system and compiler can be explicitly derived from the Array class. The user should use the array provided by the language to construct.

An element is a value in Array. The length of an Array is the total number of elements it can contain. The rank of Array is the dimension in Array. The lower limit of a dimension in Array is the starting index of the dimension in Array. Each dimension of multi-dimensional Array can have different boundaries.

Important:

In. NET Framework 2.0, the Array class implements System. Collections. Generic. IList, System. Collections. Generic. ICollection, and System. Collections. Generic. IEnumerable Generic interfaces. Since the implementation is provided to the array at runtime, it is invisible to the document generation tool. Therefore, the generic interface does not appear in the Declaration syntax of the Array class, nor does it have to forcibly convert the Array to the generic interface type (implemented by the explicit interface) the Reference topic of the interface members that can be accessed. To forcibly convert an array to these three interfaces, note that adding, inserting, or removing elements will cause NotSupportedException.

Since Array is implemented by System. Collections. Generic. IList, System. Collections. Generic. ICollection, and System. Collections. Generic. IEnumerable. Array is composed of a linked list, a set, and an enumerator.

The Array. Copy method not only copies elements between arrays of the same type, but also between standard arrays of different types. It automatically performs forced type conversion.

(4) Whether ToArray consumes more time and space

MSDN: the element uses System. Array. Copy for copying. The latter is an O (n) operation, where n is Count.

The computational complexity of this method is O (n), where n is Count.

This indicates that ToArray requires additional memory space to store new arrays.

(5) can int [] be regarded as an abbreviated form of Array <int>?

Related Article

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.