Difference between default value as: new string(){} and default value as: 'nothing entered i.e. blank' when creating a String Array?

What is the difference between entering default value as new string(){} and not entering a default value when creating a String Array?

Hi @Akash_Malpure

If a variable have a default value, the object will be created that you can use it’s method immediately like:
array.Count
Otherwise, you will get a null exception when you do so.

Hi @Akash_Malpure

From my understanding, if you don’t assign anything, the variable is basically null. If you check if that array is Nothing, it will return true. But when you assign it as new string(){}, it is basically creating a memory for that variable. It will be an array of length zero i.e. no value array. Entering default value for array seems valid to me when you enter some values for example, new string(){“A”,“B”,“C”} and not blank array as it will unnecessarily add memory.

Hope it helps!

2 Likes

Declaration means that variable is only declared and memory is allocated, but no value is set.
However, definition means the variables has been initialized.
Eg.,
Declaring a variable:
int x;

Let’s define and assign a value:
x = 10;

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.