HomeCSharpC# Error CS1921 – The best overloaded method match for ‘{0}’ has wrong signature for the initializer element. The initializable Add must be an accessible instance method.

C# Error CS1921 – The best overloaded method match for ‘{0}’ has wrong signature for the initializer element. The initializable Add must be an accessible instance method.

C# Error

CS1921 – The best overloaded method match for ‘{0}’ has wrong signature for the initializer element. The initializable Add must be an accessible instance method.

Reason for the Error & Solution

The best overloaded method match for ‘method’ has wrong signature for the initializer element. The initializable Add must be an accessible instance method.

This error is generated when you try to use a collection initializer with a class that has no public non-static Add method. If the Add method is not accessible because of its protection level (private, protected, internal) then you will get CS0122, so that this error probably means that the method is defined as static.

Example

The following example generates CS1921:

// cs1921.cs  
using System.Collections;  
public class C : CollectionBase  
{  
    public static void Add(int i)  
    {  
    }  
}  
public class Test  
{  
    public static void Main()  
    {  
        var collection = new C { 1, 2, 3 }; // CS1921  
    }  
}  

Leave A Reply

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

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