Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
what is the following code doing

C#
int[] lstNumbers = p.RandomNumbers();
                       int[,] array = new int[3, 3];


in this method

C#
int k = 1;
                        int[] lstNumbers = p.RandomNumbers();
                        int[,] array = new int[3, 3];

                        for (int i = 0; i < 3; i++)
                        {
                            for (int j = 0; j < 3; j++)
                            {
                                array[i, j] = lstNumbers[k - 1];
                                k++;
                            }

                        } 


actually i just want to know int[,] array =new int [3,3]

it will create a 3 row and 3 columns matrix but why we write int[,]??
Posted

Maybe you should take a look at MSDN.

http://msdn.microsoft.com/en-us/library/2yd9wwz4.aspx[^]

int i[,] tells the compiler that it is a multi dimensional array with two dimensions.
Then in the next part new int [3,3] you tell the compiler the length of each dimension.
Simple as that.
 
Share this answer
 
Comments
[no name] 7-Jul-14 1:31am    
that why it was giving problem when i removed the , from [,]
[no name] 7-Jul-14 1:32am    
thanks a lot
George Jonsson 7-Jul-14 1:37am    
You're welcome.
Hi,

Go through This link : http://msdn.microsoft.com/en-us/library/aa288453(v=vs.71).aspx[^]

it will answer all of your questions.

:)
 
Share this answer
 
Comments
[no name] 7-Jul-14 1:32am    
thank you too
Suvabrata Roy 7-Jul-14 2:24am    
welcome

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900