C# Return type error

后端 未结 2 660
天命终不由人
天命终不由人 2021-01-26 07:40

So here is my code:

public class landen
{
    public static List Lijst()
    {
        List lijst = new List
        {
               


        
相关标签:
2条回答
  • 2021-01-26 08:22

    This sort of error occurs if you have a custom List class, and it is less accessible than the method itself.

    Consider making your custom list public. That should solve the problem.

    0 讨论(0)
  • 2021-01-26 08:32

    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.

    0 讨论(0)
提交回复
热议问题