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
Recipeclass public.