简体   繁体   English

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

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

In my Excel Add-In, I have created two task panes - with each ones visibility being from two different values, requiring both to be in a return statement, however it will only allow me to return one of the values. 在我的Excel加载项中,我创建了两个任务窗格-每个任务窗格的可见性都来自两个不同的值,要求这两个值都在return语句中,但是它仅允许我返回其中一个值。 These are 'taskPaneValue' and 'taskPaneValue2'. 这些是“ taskPaneValue”和“ taskPaneValue2”。

How do I go about having both returned in the 'get' statement. 如何在“ 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;
        }

    }

The final 'get' statement is the one I wish to return both variables. 最后一个“ get”语句是我希望返回两个变量的语句。

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

You can also create a method with out parameter modifier, if it'still possible to you. 如果仍然可以,也可以使用out参数修饰符创建一个方法。 Please, check the following link: https://msdn.microsoft.com/en-us/library/ee332485.aspx 请检查以下链接: https : //msdn.microsoft.com/en-us/library/ee332485.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM