HomeCSharpC# Error CS0747 – Invalid initializer member declarator

C# Error CS0747 – Invalid initializer member declarator

C# Error

CS0747 – Invalid initializer member declarator

Reason for the Error & Solution

Invalid initializer member declarator.

An object initializer is used to assign values to properties or fields. Any expression which is not an assignment to a property or field is a compile-time error.

To correct this error

  1. Ensure that all expressions in the initializer are assignments to properties or fields of the type. In the following example, the second expression is an error because the value 1 is not assigned to any property or field of List<int>.

Example

The following code generates CS0747:

// cs0747.cs  
using System.Collections.Generic;  
  
public class C  
{  
    public static int Main()  
    {  
        var t = new List<int> { Capacity = 2, 1 }; // CS0747  
        return 1;  
    }  
}  

Leave a Reply

You May Also Like

This C# program calculates and displays an upper triangular matrix based on user input. Problem Statement: The program takes the...
This C# program serves as a demonstration of bitwise operators, which are fundamental operators used for manipulating individual bits in...
This C# program is designed to interchange or swap the columns of a matrix. A matrix is a two-dimensional array...