Does not contain a constructor that takes 0 arguments

后端 未结 5 1544
悲哀的现实
悲哀的现实 2020-11-30 03:33

I get an error stating "Products does not contain a constructor that takes 0 arguments" from the following code:

public class Products
{
    string          


        
5条回答
  •  醉话见心
    2020-11-30 04:34

    Just add

    public Products()
    {
    
    }
    

    in your products class And you will not get error

    Reason: There exists a default constructor with 0 parameter for every class. So no need to define/write it explicitly (by programmer) BUT when you overload a default constructor with your desired number and type of parameters then it becomes a compulsion to define the default constructor yourself (explicitly) along with your overloaded constructor

提交回复
热议问题