General understanding C #(21. pointer operation-22. Multi-dimensional array)

Source: Internet
Author: User

21. pointer operation

In C #, pointer operations can be used in Methods labeled as unsafe modifiers. When the pointer points to an object that can be garbage collected, the compiler forces the fixed keyword to fix the object. This is because the Garbage Collector recycles memory by moving objects. However, if you use the original pointer and the object it refers to is moved, your pointer will point to garbage. I think using the keyword "unsafe" is a good choice-it does not encourage developers to use pointers unless they really want to do so.

22. Multi-dimensional array

C # You can create an interleaved array. The dimensions and sizes of the elements in the staggered array can be different] and multi-dimensional arrays. The staggered array is very similar to the Java array. Multi-dimensional arrays allow you to express specific problems more effectively and accurately. The following is an example of this array:

Int [,] array = new int [3, 4, 5]; // create an array

Int [, 1] = 5; // This line of code is incorrect: array [, 1] = 5 ;]

Use an interleaved array:

Int [] [] [] array = new int [3] [4] [5]; // This line of code is incorrect and should be: int [] [] [] array = new int [3] [] [];]

Int [1] [1] [1] = 5; [: This line of code is incorrect: it should be array [1] [1] [1] = 5;] [: use the staggered array with caution]

If used in combination with the structure, the efficiency provided by C # Makes arrays a good choice in the graphic and mathematical fields.

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.