错误1不一致的可访问性:返回类型比方法更不可访问 [英] Error 1 Inconsistent accessibility: return type is less accessible than method

查看:217
本文介绍了错误1不一致的可访问性:返回类型比方法更不可访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在构建时,VS显示错误。这是我的代码:

When I'm building, VS show error. This is my code:

public Composite buildComposite(ComboBox subs, ComboBox bas)
{
    int count = 0;
    Composite a = new Composite();
    if (subs.SelectedItem != null)
    {
        foreach (Substance d in listSubstance)
        {
            if (String.Compare(d.notation, subs.Text) == 0)
            {
                count++;
                a.subs = new Substance(d);
                break;
            }
        }
    }
    if (bas.SelectedItem != null)
    {
        foreach (Base g in listBase)
        {
            if (String.Compare(g.notation, bas.Text) == 0)
            {
                count++;
                a.bas = new Base(g);
                break;
            }
        }
    }
    if (count > 0)
    {
        a.equilibrium();
        a.settypesubs(arrayDefinition);
        return a;
    }
    else
        return null;
}

这是我的错误:


错误1不一致的可访问性:返回类型'Project_HGHTM9.Composite'比方法'Project_HGHTM9.Form1.buildComposite(System.Windows.Forms.ComboBox,System.Windows.Forms.ComboBox )'c:\users\nguyen\documents\visual studio 2013\Projects\Project_HGHTM9\Project_HGHTM9\Form1.cs 172 26 Project_HGHTM9

Error 1 Inconsistent accessibility: return type 'Project_HGHTM9.Composite' is less accessible than method 'Project_HGHTM9.Form1.buildComposite(System.Windows.Forms.ComboBox, System.Windows.Forms.ComboBox)' c:\users\nguyen\documents\visual studio 2013\Projects\Project_HGHTM9\Project_HGHTM9\Form1.cs 172 26 Project_HGHTM9


推荐答案

您的综合类不是 public 。您不能通过公共方法返回非公共类型。

Your Composite class is not public. You can't return a non-public type from a public method.

如果您未为非嵌套类指定可访问性,则内部。将 public 添加到您的 Composite 类定义中:

If you don't specify an accessibility for a non-nested class then internal is used by default. Add public to your Composite class definition:

public class Composite
{
    ...

或者,如果 buildComposite 不需要 成为公开(这是唯一的在表单内部使用),那么您还可以将方法 private 设置为:

Alternatively, if buildComposite doesn't need to be public (meaning it's only used internally by the form), then you could make the method private as well:

private Composite buildComposite(ComboBox subs, ComboBox bas)
{
    ....

这篇关于错误1不一致的可访问性:返回类型比方法更不可访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆