How to Use T [] or List & lt; T & gt; in C ;,

Source: Internet
Author: User

How to Use T [] or List <T> in C,


If a group of data needs to be stored, does it use T [] or select List <T>?

 

First, let's look at the array.

 

All Array types are implicitly derived from the abstract class System. Array, and System. Array is derived from System. Object. That is to say, the array is of reference type. Create an array as follows:

 

Int [] arrInt = new int [10];

 

The above memory blocks are allocated on the hosting stack to accommodate 10 unboxed int objects (this memory block can accommodate the memory occupied by array elements, it also includes the type object pointer of the array element object, synchronization block index and other additional members), and then the memory block address is returned and saved to the arrInt variable on the thread stack.


In fact, an array is maintained internally, but the size of the array can be dynamically increased. As mentioned here.

Summary: if the data capacity changes dynamically, You need to perform operations, such as inserting or deleting elements, use List <T>. If the data capacity is fixed, you can consider using T [].

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.