C#错误 - 由于可选参数或其他原因?

时间:2015-08-12 18:47:34

标签: c#

这是我的代码:

    public void RemovalWorker_Start(Applications app = null, Link link = null)
    {
        BackgroundWorker RemovalWorker = new BackgroundWorker();
        RemovalWorker.DoWork += RemovalWorker_DoWork;
        RemovalWorker.RunWorkerCompleted += RemovalWorker_RunWorkerCompleted;
        RemovalWorker.WorkerSupportsCancellation = true;
        RemovalWorker.RunWorkerAsync(arg);
    }
    private void RemovalWorker_DoWork(object sender, DoWorkEventArgs e)
    {
        var app = e.Argument.GetType();
        if(app.Name == "Applications")
        {
            Applications RemovalAppliction = (Applications)e.Argument;
            RemovalAppliction.RemoveApplication();
            Dispatcher.Invoke(new Action(() =>
            {
                user.RemoveFromMyApps(user._MyApps[listBox_apps.SelectedIndex]);
            }));
            e.Result = "apps";
        }
        else
        {
            Link RemovalLink = (Link)e.Argument;
            RemovalLink.RemoveLink();
            Dispatcher.Invoke(new Action(() =>
            {
                user.RemoveFromMyLinks(user._MyLinks[listBox_links.SelectedIndex]);
            }));
            e.Result = "links";
        }

    }

我正在尝试将可选参数传递给我的RemovalWorker。但是,我收到以下错误:

Inconsistent Accessibility: parameter type 'Applications' is less accessible than method 'MainWindow.RemovalWorker_Start(Applications,Link)'
Inconsistent Accessibility: parameter type 'Link' is less accessible than method 'MainWindow.RemovalWorker_Start(Applications,Link)'

为什么会这样?我是否错误地声明了可选参数?我该怎么办呢? “删除工作程序”通过按钮单击实例化(命中列表框项目上的删除)。我想传递的论点是它是“应用程序”对象还是“链接”对象。

该函数不是100%完成 - 我仍然需要声明我的参数是什么,但是,我目前无法编译。

全部谢谢!

1 个答案:

答案 0 :(得分:3)

我猜你的应用程序和链接是你自己的类,它不是公共类

所以,当你公开无效时,RemovealWorker_Start此行中的公众与非公开的应用程序和链接冲突