How to declare a constructor?

后端 未结 3 740
逝去的感伤
逝去的感伤 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:33

    You have error in two lines:

    var selectionDisplay = new SelectionDisplay(button.Label as string, button.Tag as string);
    

    and

    var selectionDisplay = new SelectionDisplay(button.Label, button.Background); 
    

    and you define the constructor as

    public SelectionDisplay(string itemId)
        {
            this.InitializeComponent();
    
            this.messageTextBlock.Text = string.Format(CultureInfo.CurrentCulture,Properties.Resources.SelectedMessage,itemId);
    
        }
    

    if you need to define with some default value then you need to do like this

    public SelectionDisplay(string itemId, string nextParam="default value")
        {
            this.InitializeComponent();
    
            this.messageTextBlock.Text = string.Format(CultureInfo.CurrentCulture,Properties.Resources.SelectedMessage,itemId);
    
        }
    

    In this case you can either pass next argument or ignore it

提交回复
热议问题