Click here to Skip to main content
15,920,596 members
Home / Discussions / C#
   

C#

 
AnswerRe: How Can i Create A Class Library For MSACCESS database Connection Pin
ambarishtv28-Apr-11 6:27
ambarishtv28-Apr-11 6:27 
QuestionListBox.PreferredSize.Width interesting event Pin
msn9224-Apr-11 4:33
msn9224-Apr-11 4:33 
AnswerRe: ListBox.PreferredSize.Width interesting event Pin
DaveyM6924-Apr-11 12:30
professionalDaveyM6924-Apr-11 12:30 
QuestionArray Pin
messages23-Apr-11 1:40
messages23-Apr-11 1:40 
AnswerRe: Array PinPopular
David198723-Apr-11 2:15
David198723-Apr-11 2:15 
GeneralRe: Array Pin
messages23-Apr-11 2:20
messages23-Apr-11 2:20 
GeneralRe: Array Pin
David198723-Apr-11 3:08
David198723-Apr-11 3:08 
AnswerRe: Array Pin
OriginalGriff23-Apr-11 8:23
mveOriginalGriff23-Apr-11 8:23 
What David means is: Every time you create an array, you have to initialize it:
int[] test = new int[3];
Declares a variable that refers to an array of integers, calls it test, and assigns an array of three integers to it. You can now use test[0], test[1], and test[2] perfectly happily.
int[][] test = new int[3][];
Declares a variable that refers to an array of arrays of integers, calls it test, and assigns an array of three integer arrays to it. It does not assign the arrays of integers. To do that, you either need a static declaration, or a loop:
int[][] test = new int[3][] { new int[] { 1, 2, 3 },
                              new int[] { 4, 5, 6 },
                              new int[] { 7, 8, 9, 10 } };
Or:
int[][] test = new int[3][];
for (int i = 0; i < test.Length; i++)
    {
    test[i] = new int[3];
    }
You need to repeat the process for each layer of array of arrays you add! Beware: arrays of arrays start to take significant amounts of space, very, very quickly...

These are all "jagged" arrays: the inner arrays are not necessarily the same size.
You can also declare rectangular arrays:
int[,] test = new int[3,4];
This declares a rectangular array of 12 elements in total, and assigns them all. You can happily use test[0,0], test[0,1]... etc.

You can combine them as you did in your example:
int[,][] test = new int[3,4][];
Declares a rectangular array of 12 jagged arrays. You have to initialize each of these to a new array of ints before you can use them, either statically, or in a loop as before.


Note: Normally, I would recommend using a foreach loop rather than a for loop, but that is not possible when filling in jagged arrays, as you cannot change the loop variable:
int[][] test = new int[3][];
foreach (int[] inner in test)
    {
    inner = new int[3];
    }
Will give you a compilation error.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

Manfred R. Bihy: "Looks as if OP is learning resistant."

GeneralRe: Array Pin
Prasanta_Prince23-Apr-11 18:52
Prasanta_Prince23-Apr-11 18:52 
GeneralRe: Array Pin
messages23-Apr-11 19:56
messages23-Apr-11 19:56 
GeneralRe: Array Pin
David198723-Apr-11 20:04
David198723-Apr-11 20:04 
GeneralRe: Array Pin
OriginalGriff23-Apr-11 21:17
mveOriginalGriff23-Apr-11 21:17 
GeneralRe: Array Pin
messages23-Apr-11 19:54
messages23-Apr-11 19:54 
AnswerRe: Array Pin
Abhinav S25-Apr-11 1:29
Abhinav S25-Apr-11 1:29 
AnswerRe: Array Pin
ambarishtv28-Apr-11 6:36
ambarishtv28-Apr-11 6:36 
QuestionGZipStream ends too early Pin
Paladin200022-Apr-11 10:09
Paladin200022-Apr-11 10:09 
AnswerRe: GZipStream ends too early Pin
Andrew Rissing22-Apr-11 15:55
Andrew Rissing22-Apr-11 15:55 
GeneralRe: GZipStream ends too early Pin
Paladin200025-Apr-11 3:43
Paladin200025-Apr-11 3:43 
GeneralRe: GZipStream ends too early Pin
Andrew Rissing25-Apr-11 4:05
Andrew Rissing25-Apr-11 4:05 
QuestionUnable To Deserialize Pin
Anubhava Dimri22-Apr-11 0:36
Anubhava Dimri22-Apr-11 0:36 
AnswerRe: Unable To Deserialize Pin
Not Active22-Apr-11 3:50
mentorNot Active22-Apr-11 3:50 
AnswerRe: Unable To Deserialize Pin
SledgeHammer0122-Apr-11 5:11
SledgeHammer0122-Apr-11 5:11 
GeneralRe: Unable To Deserialize Pin
DaveyM6922-Apr-11 8:07
professionalDaveyM6922-Apr-11 8:07 
GeneralRe: Unable To Deserialize Pin
Anubhava Dimri22-Apr-11 18:11
Anubhava Dimri22-Apr-11 18:11 
Questiongraph adjacency matrix Pin
Alex25221-Apr-11 20:15
Alex25221-Apr-11 20:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.