Array CLR course 13th

Source: Internet
Author: User

1. arrays are reference types, while arrays of value types are also reference types.
 
2. Int [] Myint; Myint = new int [100];
First, Myint is mysteriously regarded as a one-dimensional array variable pointing to the element type Int. At this time, Myint is set to null.

. When an array of 100 int values is allocated, all these int element values are initialized to 0. Although Int Is of the Value Type

Memory blocks that save the int values are allocated from the managed heap. The memory contains 100 boxed int

Value, lastCodeReturn the memory block address that saves the int value and save it in the variable Myint.

Control [] myctr; myctr = new control [50];
First, myctr is set to null, and then an array containing 50 control references is allocated.

Control references are initialized to null, because control belongs to the reference type, all

It is a reference, not an actual object. The final code returns the memory address that saves the reference and saves it in

Variable in myctr.

3. Try to use a 0-base array, which has the best performance and is compatible with Cls (the staggered array is not compatible.

CLs); if the index exceeds the limit, the system. indexoutofrangeexception is thrown.

4. All arrays are inherited from system. array, which implements icloneable, ienumerable,

Icollection and ilist interfaces; CLR does not allow the conversion of arrays whose elements are value types to any other types,

It is through, array. Copy (bind the value type to the reference type; bind the reference type to the value type, broaden

CLR primitive type), and it is a shortest copy. Array of referenced elements, which can be displayed

Or implicitly converted to another type.
5. arrays are always passed to the method in reference mode. array. copy is a shortest copy. If the elements in the source array

Element is the reference type. The elements in the new array returned by this method are the objects referenced by the elements in the source array.

The deep COPY method of the current array is to implement the icloneable interface to serialize an object to

System. Io. memorystream, and then immediately deserialize the memory stream to obtain a new

Object, performance loss, and possibly all objects are serialized.

6. You can create an array whose lower limit is not 0 and use the array. createinstance method.

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.