Edit

Share via


Compiler Error CS1526

A new expression requires (), [], or {} after type

The new operator, used to dynamically allocate memory for an object, was not specified correctly.

Example

The following sample shows how to use new to allocate space for an array and an object.

C#
// CS1526.cs  
public class y
{
    public static int globalCounter = 0;
    public int instanceCounter = 0;
}

public class z
{
    public static void Main()
    {
        y yInstance = new y;   // CS1526  
        y[] yArray = new y[10];   // Array of Ys  

        for (int i = 0; i < yArray.Length; i++)
            yArray[i] = new y();   // an object of type y  
    }
}