在C#'get'语句中返回多个变量

时间:2017-01-23 20:46:42

标签: c# get return vsto

在我的Excel加载项中,我创建了两个任务窗格 - 每个窗格的可见性来自两个不同的值,要求两者都在return语句中,但是它只允许我返回其中一个值。这些是'taskPaneValue'和'taskPaneValue2'。

如何在'get'语句中返回两者。

private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {
        taskPaneControl2 = new FileChooser();
        taskPaneValue2 = this.CustomTaskPanes.Add(taskPaneControl2, "File Chooser");
        taskPaneValue2.VisibleChanged += new EventHandler(taskPaneValue_VisibleChanged);

        taskPaneValue2.DockPosition = Office.MsoCTPDockPosition.msoCTPDockPositionFloating;
        taskPaneValue2.Height = 600;
        taskPaneValue2.Width = 600;

        taskPaneValue2.DockPositionRestrict = Office.MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoChange;

        //These three lines of code start by initiating the TaskPane control (namely aLaCarteMenu()) 
        //It then goes on to set the name of the menu "A La Carte Menu" which appears on the top left of the window before stating its visibility.
        taskPaneControl1 = new aLaCarteMenu();
        taskPaneValue = this.CustomTaskPanes.Add(taskPaneControl1, "A La Carte Menu");
        taskPaneValue.VisibleChanged +=

        //The following four lines of code are used to display the visiblity of the AddIn.
        //The docking position is set to float, with a resolution of 980x1920.  This is designed for a 1080p screen, however still working on changing it to fit screens dynamically.
        new EventHandler(taskPaneValue_VisibleChanged);
        taskPaneValue.DockPosition = Office.MsoCTPDockPosition.msoCTPDockPositionFloating;
        taskPaneValue.Height = 980;
        taskPaneValue.Width = 1920;

        //This line of code sets the position to be restricted to what has been set above (floating).  This allows for the pane to be moved around the screen, as well as to be resized. 
        //This stops the pane from locking on to the right, left, top or bottom sections of the Excel Window.
        taskPaneValue.DockPositionRestrict = Office.MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoChange;


}

private void taskPaneValue_VisibleChanged(object sender,     System.EventArgs e)
    {
        Globals.Ribbons.ManageTaskPaneRibbon.toggleButton1.Checked = taskPaneValue.Visible;
        Globals.Ribbons.ManageTaskPaneRibbon.toggleButton2.Checked = taskPaneValue2.Visible;

    }

    public Microsoft.Office.Tools.CustomTaskPane TaskPane
    {
        get
        {
            return taskPaneValue2;
        }

    }

最后的'get'语句是我希望返回两个变量的语句。

2 个答案:

答案 0 :(得分:1)

使用Tuple或创建一个具有您正在寻找的所有属性的类,并将其作为函数的返回类型。

答案 1 :(得分:1)

如果你可能的话,你也可以用out参数修饰符创建一个方法。请检查以下链接:https://msdn.microsoft.com/en-us/library/ee332485.aspx