Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
756 views
in Technique[技术] by (71.8m points)

c# - Error 1 Inconsistent accessibility: return type is less accessible than method

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;
}

This is my error:

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 guyendocumentsvisual studio 2013ProjectsProject_HGHTM9Project_HGHTM9Form1.cs 172 26 Project_HGHTM9

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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
{
    ...

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 or internal as well:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...