arrays, multidimensional arrays, and jagged arrays in C #

Source: Internet
Author: User

Want to study some object-oriented things, perhaps the code is not written enough. Feel bad, look at those tutorials, not too much water is too ugly do not understand. The mood is very lonely

However, you should continue to send a blog every day.

Here's a look at some of the things in C # that are arrays, multidimensional arrays, and jagged arrays.

There's a little bit of research on anise Bean's anise with four different ways of writing it.

Let's talk about three things that are obvious and worth mentioning.

The 1th array is a data structure

There seems to be no good explanation.

The 2nd array type is a reference type derived from the abstract class array

Unlike the arrays in C, C # is designed in an object-oriented fashion.

So prove again that everything is an object.

An array of 3rd C # can be opened very large

c directly on the stack different and C # arrays are only referenced in the managed stack, and the actual data is placed inside the managed heap.

Int[,,] a = new int[500, 500, 500];

It's not going to be a problem. The same size in C early ... Had

That said, normal use is unlikely to be used in such a large array.

The 4th array type can use a foreach iteration

This Part I want to write another article to study this

There are also a few things you can refer to in the MSDN array section

Http://msdn.microsoft.com/zh-cn/library/9b9dty7d%28VS.80%29.aspx

And then, let's start with the code.

[C-sharp]  View plain  copy//one-dimensional array    int[] a1 = new int[3];   INT[] A2  = new int[] { 0, 1, 2 };   int[] a3 = {  0, 1, 2 };   int[] a4;   a4 = new int[3] { 0,  1, 2 };  //int[3] a5;  error code   //int a5[3];  error code     a1[0] = 0;   Console.WriteLine ("{0}", a1[0]);  //multidimensional Data    int[,]  b1 = new int[3, 3];   int[,] b2 = new int[,] {{ 0,1,2},                            {0,1,2},                            { 0,1,2}};   int[,] b3 = new int[,] {{0,1,2},                             {0,1,2},                            {0,1,2}};   int[,] b4;    b4 = new int[,]{{0,1,2},                    {0,1,2},                    {0,1,2}};   int[, ,] b5 =  new int[2,2,2] {{{1,2},{1,2}},                                   {{1,2},{1,2}}};   b5[0,0,0] = 1;   Console.WriteLine ("{0}", b5[0,0,0]);  // Jagged Array (array of arrays)    int[][] c1 = new int[3][];   c1[0] = new  int[3];   c1[1] = new int[2];   c1[2] = new int[1];    int[][] c2 = new int[][]   {       new  int[] {1,2,3},       new int[] {4,5,6},        new int[] {7,8,9}  };   int[][] c3 =   {        new int[] {1,2,3},  

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.