C# Error CS1955 – Non-invocable member ‘{0}’ cannot be used like a method.

C# Error

CS1955 – Non-invocable member ‘{0}’ cannot be used like a method.

Reason for the Error & Solution

Non-invocable member ‘name’ cannot be used like a method.

Only methods and delegates can be invoked. This error is generated when you try to use empty parentheses to call something other than a method or delegate.

To correct this error

  1. Remove the parentheses from the expression.

Example

The following code generates CS1955 because the code is trying to invoke a field and a property by using the . You cannot call a field or a property. Use the to access the value it stores.

// cs1955.cs  
class A  
{  
    public int x = 0;  
    public int X  
    {  
        get { return x; }  
        set { x = value; }  
    }  
}  
  
class Test  
{  
    static int Main()  
    {  
        A a = new A();  
        a.x(); // CS1955  
        a.X(); // CS1955  
        // Try this line instead:  
        // int num = a.x;  
    }  
}  

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