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

标签 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)'

为什么会这样?我是否错误地声明了我的可选参数?我应该如何解决这个问题? “删除 worker ”是通过单击按钮(点击列表框项目上的删除)来实例化的。我想传递的参数是它是“应用程序”对象还是“链接”对象。

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

谢谢大家!

最佳答案

我猜你的 Applications 和 Link 是你自己的类,不是公共(public)类

所以当你在 public void RemovalWorker_Start public 这行与 Applications 和 Link 的 nonpublic 冲突时

关于C# 错误 - 由于可选参数或其他原因?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31973124/

相关文章:

c# - 命令 '/bin/sh -c dotnet restore ./DockerTestDebian.csproj' 返回非零代码 : 1

c# - SingleOrDefault,default怎么写出来?

c# - 将字符串数组转换为整数数组

javascript - MVC 和 HTML5 验证 : conflict with the decimal format

c# - 使用 LINQ 获取序列的奇数/偶数部分

c# - 在 C# 中读取 gml

c# - 并行线程中的多个 dbcontext,EntityException "Rerun your statement when there are fewer active users"

c# - 使用 bool 值的多个 orderby linq 查询

c# - 获取存储在 VirtualStore 中的日志文件的真实路径

c# - 如何在 C# 中将任何类型的数字作为参数接受到函数中?