Question: What is meaning of 

```
public static int[,] key { get; set; }

```

in C# ? Please explain as am newbie to this language and also what size of 2D array will be allotted to this key array ?

Here is code . I dont get how to remove error from it

```
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Testing
{
    class Program
    {
        public static int[,] key { get; set; }

        public static int myfunc(int rowsize, int colsize)
        {

            int num3=0;
            for (int index2 = 0; index2 < rowsize; ++index2)
            {
                for (int index4 = 0; index4 < colsize; ++index4){
                   num3 += key[index2, index4];
                   Console.WriteLine(num3);
                }
            }  
            return num3;
        }

        static void Main(string[] args)
        {
            Console.WriteLine(myfunc(3, 5));
        }
    }
}

```

Answer: 
You are not initializing array, so it is null. When you write `key[index2, index4]` you actually ask your array to give you value at row `index2` and column `index4`. But as the array is null you will get `NULLReference exception`.

All you should do is initialize array like:

```
key = new int[3, 5];
Console.WriteLine(myfunc(3, 5));

```

It will fill your array with default values of type int, i.e. 0s.
If you want to initialize array with some values you can do it like this:

```
key = new int[3, 5] { { 1, 1, 1, 1, 1 }, { 2, 2, 2, 2, 2 }, { 3, 3, 3, 3, 3 } };
Console.WriteLine(myfunc(3, 5));

```

[3,5] means that your array has 3 rows and 5 columns. So it's actually a matrix:

```
((A00, A01, A02, A03, A04)
(A10, A11, A12, A13, A14)
(A20, A21, A22, A23, A24))

```
> 
> What is meaning of  
> 
>  public static int[,] key { get; set; }
> 
> 
> 

It's called [Auto Implemented Property](https://msdn.microsoft.com/en-us/library/bb384054.aspx).
It is just a short way of writing a full property. It compiles same as:

```
    private int[,] _key;
    public int[,] Key
    {
        get { return _key; }
        set { _key = value; }
    }

```

> 
> what size of 2D array will be allotted to this key array ?
> 
> 
> 

It will be a null reference until you assign it a value. No memory will be allocated until then.

That being said, In your code it seems that you are assuming that the `key` is being assigned somewhere out of the scope of the code you have published. If it is not, you will get a [NullReferenceException](https://msdn.microsoft.com/en-us/library/system.nullreferenceexception%28v=vs.110%29.aspx). 

You can assign the matrix like this: 

```
 int[,] key = new int[100, 50];

```

And when you access it, you can check if the indexes are valid like this:

```
 var d0 = key.GetLength(0); //100
 var d1 = key.GetLength(1); //50

```

So, you can fix your code by assigning the `key` property:

```
    static void Main(string[] args)
    {
        key = new int[100, 50];

        var d0 = key.GetLength(0);
        var d1 = key.GetLength(1);

        System.Random random = new System.Random();

        for (int i = 0; i < d0; ++i)
            for (int j = 0; j < d1; ++j)
                key[i, j] = random.Next();

        Console.WriteLine(myfunc(3, 5));
    }

```