C# Inconsistent accessibility: return type is less accessible than method

后端 未结 1 1990
一向
一向 2021-01-18 11:08

Im working on a app for my study. now i just started a app where i got a database with the soccer league\'s and the clubs etc. now i had a list with the club and the players

相关标签:
1条回答
  • 2021-01-18 11:15

    You must make your class public:

    public class Competitie
    

    If you don't specify the access modifier, it defaults to being internal (i.e.accessible only within the assembly it's compiled into).

    As the error says, the class must be at least as accessible as the method which returns it.

    The way you've got it now, there's a chance that code which can call the GetAllCompetities() method (because it's public) cannot access the class which the method returns. And clearly that is not a logical situation - the calling code would not be able use or understand the data it gets back.

    N.B. Depending on the context, it might actually be more appropriate instead to mark the GetAllCompetities() method as internal to match the class. That way none of it is accessible outside the assembly. It's entirely dependent on your situation and what you need, though. I'm just noting that for completeness. It would resolve the error, but result in a different level of accessibility for these pieces of code.

    Here is the documentation for C# access modifiers: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/access-modifiers

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