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

Returning more than one variable in a C# 'get' statement

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

如何在 'get' 语句中同时 returned。

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' 语句是我希望 return 两个变量的语句。

使用元组或创建一个 class 具有您要查找的所有属性,并使其成为函数的 return 类型。

如果仍然可行,您也可以创建一个不带参数修饰符的方法。请检查以下 link:https://msdn.microsoft.com/en-us/library/ee332485.aspx