Alex Rivera | Logout

What is the default value of a member in an array?

Asked 2013-03-08T17:41:58.447
40

I instantiate an array like this:

int array[] = new int[4];

What are the default values for those four members? Is it null, 0 or not exists?

Edit
Report

1 Answer

18

The default value of an automatically-initialized variable of type T, such as an array element or an instance field, is the same as the value of default(T). For reference types and pointer types, it's null. For numeric types, it is the zero of that type. For bool, it's false. For struct types, it is the struct value that has all its fields initialized to their default values.

answered 2013-03-08T17:45:18.557

Your Answer