C# Error CS1528 – Expected ; or = (cannot specify constructor arguments in declaration)

C# Error

CS1528 – Expected ; or = (cannot specify constructor arguments in declaration)

Reason for the Error & Solution

Expected ; or = (cannot specify constructor arguments in declaration)

A reference to a class was formed as if an object to the class was being created. For example, there was an attempt to pass a variable to a constructor. Use the operator to create an object of a class.

The following sample generates CS1528:

// CS1528.cs  
using System;  
  
public class B  
{  
   public B(int i)  
   {  
      _i = i;  
   }  
  
   public void PrintB()  
   {  
      Console.WriteLine(_i);  
   }  
  
   private int _i;  
}  
  
public class mine  
{  
   public static void Main()  
   {  
      B b(3);   // CS1528, reference is not an object  
      // try one of the following  
      // B b;  
      // or  
      // B bb = new B(3);  
      // bb.PrintB();  
   }  
}  

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