How to declare a constructor?

后端 未结 3 736
逝去的感伤
逝去的感伤 2021-01-28 07:42

I get the following error when I compile the program

\"Microsoft.Samples.Kinect.ControlsBasics.SelectionDisplay\' does not contain a constructor that ta

3条回答
  •  自闭症患者
    2021-01-28 08:23

    You should create an overload of SelectionDisplay's contructor or change the one you already have. Like this:

    public SelectionDisplay(string itemId, string tag)
    {
        //Do something here
    }
    

    Due to you're creating a new instance of SelectionDisplay with two arguments, but its constructor only accept one argument. (string itemId):

    //foreach
    new SelectionDisplay(button.Label as string, button.Tag as string); //
    
    //KinectTileButtonClick method
    new SelectionDisplay(button.Label, button.Background);
    

    You have to check what type button.Label, button.Tag and button.Background are and create a new constructor with these values.

    You can read more about Constructors here

提交回复
热议问题