C# Error CS1526 – A new expression requires an argument list or (), [], or {} after type

C# Error

CS1526 – A new expression requires an argument list or (), [], or {} after type

Reason for the Error & Solution

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

The 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.

// CS1526.cs  
public class y  
{  
   public static int i = 0;  
   public int myi = 0;  
}  
  
public class z  
{  
   public static void Main()  
   {  
      y py = new y;   // CS1526  
      y[] aoys = new y[10];   // Array of Ys  
  
      for (int i = 0; i < aoys.Length; i++)  
         aoys[i] = new y();   // an object of type y  
   }  
}  

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...