C# Error CS0622 – Can only use array initializer expressions to assign to array types. Try using a new expression instead.

C# Error

CS0622 – Can only use array initializer expressions to assign to array types. Try using a new expression instead.

Reason for the Error & Solution

Can only use array initializer expressions to assign to array types. Try using a new expression instead.

Syntax that is appropriate to initialize an array was used in the declaration of a non-array.

Example

The following sample generates CS0622:

// CS0622.cs  
using System;  
  
public class Test  
{  
    public static void Main ()  
    {  
        Test t = { new Test() };   // CS0622  
        // Try the following instead:  
        // Test[] t = { new Test() };  
    }  
}  

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