返回类型比方法访问性低 [英] return type is less accessible than method

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

问题描述

我是新来的 C#这里是从一个个人项目的摘录我的工作得到了一些经验。

在调用 getRecipe()这个类以外的功能我是psented错误如下$ P $。我想保持我的列表私有的食谱类,但仍然能够获得一个参考的一个食谱名单。我不想让我的列表公开。

任何意见大大AP preciated!谢谢


错误

 返回类型cookbook.Recipe比方法进行访问少cookbook.CookBook.getRecipe(串)'
 


 公共类食谱
{
    私人列表<配方> listOfRecipes =新的名单,其中,配方> {};
    公方getRecipe(字符串名称)
    {
        INT I = 0;
        而(listOfRecipes [I] .getRecipeName()!=名称)
        {
            我++;
        }
        返回listOfRecipes [I]
    }
}
 

解决方案

请在配方类上市。

I am new to c# and here is an excerpt from a personal project i am working on to get some experience.

When calling the getRecipe() function outside this class i am presented with the following error. I want to keep my List private to the CookBook class but still be able to get a reference to one of the Recipes in the List. I do not want to make my List public.

Any advice is greatly appreciated! Thanks


The error

return type 'cookbook.Recipe is less accessible than method 'cookbook.CookBook.getRecipe(string)'


public class CookBook
{
    private List<Recipe> listOfRecipes = new List<Recipe> {};
    public Recipe getRecipe(string name)
    {
        int i = 0;
        while (listOfRecipes[i].getRecipeName() != name)
        {
            i++;
        }
        return listOfRecipes[i];
    }
}

解决方案

Make the Recipe class public.

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

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