Julian van Heek Julian van Heek - 1 year ago 84
C# Question

C# Return type error

So here is my code:

public class landen
public static List<Land> Lijst()
List<Land> lijst = new List<Land>
new Land("AF,AFG,Afghanistan,Islamitische Republiek AFghanistan,Kaboel,0093"),
new Land("AL,ALB,Albaniƫ,Republiek Albaniƫ, Tirana,00355"),
new Land("DZ,DZA,Algerije,Democratische Volksrepubliek Algerije,Algiers,00213")
return lijst;

my error is:

Error CS0050 Inconsistent accessibility: return type
'List' is less accessible than method 'landen.Lijst()'

Answer Source

As the error is indicating, you are trying to return an instance of a class that has a visibility modifier - e.g. private, internal, protected, public - that is less accessible than your method.

As your method public static List<Land> Lijst() is public you should check for the visibility of List class.

You can only return instances of List in this case from methods that has the same or higher accessibility. Check this to know more about the restrictions when using accessibility levels:

Check this in order to know the levels of accessibility in C#.

From greater access privilege to lower:

public: Access is not restricted.

protected: Access is limited to the containing class or types derived from the containing class.

internal: Access is limited to the current assembly.

protected internal: Access is limited to the current assembly or types derived from the containing class.

private: Access is limited to the containing type.

You should have your List class defined somewhere as:

**public** class List

Maybe it's defined as internal or protected internal, or even doesn't have any modifier and then it's private and hence your are receiving this error.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download