C#C
C#11mo ago
Faker

✅ NullReferenceException when declaring an array but not initializing it

Hello guys, say I created a new class and within that new class, I created an array.
So we have something like this:

C#
class MyClass
{
  private int[] numbers;
  private string someVariable;

  public MyClass() // default constructor
{
  someVariable = "";
}

Noticed that we didn't initialize numbers array. So what will happen if we try to access it? we get a NullReferenceException? If so, what is happening internally pls. Like when we declare int[] numbers, normally numbers should store a reference to where the array is on the heap, right? But since their is no "array" yet, numbers points to nothing, so to null?
Was this page helpful?