return type is less accessible than method

Your Recipe class is less accessible than the method. You should check that Recipe is not private/internal and that you can see the Recipe class from outside that class scope (quick fix declare Recipe a public class).

As pointed out by Michael Stum in a comment below classes without an access modifier are by default either internal or private (if it's a nested class). This is possibly where your issue is and you may have just declared class Recipe instead of public class Recipe


As the error message clearly states, the Recipe class is less accessible (eg, not public) than your method.


Make the Recipe class public.


Syntax error?

private List<Recipe> listOfRecipes = new List<Recipe> {};

should be:

private List<Recipe> listOfRecipes = new List<Recipe>();

Additionally, you could simply use LINQ to get your result, I'm not in VS, but something like this...

public Recipe getRecipe(string name)
{
    return listOfRecipes.Where(c => c.RecipeName == name).SingleOrDefault();
}

Tags:

C#

.Net