Export (0) Print
Expand All
Expand Minimize

Compiler Error CS0623

Updated: October 2008

Array initializers can only be used in a variable or field initializer. Try using a new expression instead.

An attempt was made to initialize an array by using an array initializer in a context where it is not allowed.

The following example produces CS0623 because the compiler interprets the {4} as embedded array initializer inside the outer array initializer:

//cs0632.cs
using System;

class X
{
    public int[] x = { 2, 3, {4}}; //CS0623
}

Date

History

Reason

October 2008

Added text and code example.

Customer feedback.

Community Additions

ADD
Show:
© 2014 Microsoft