Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Returning List - Inconsistent Accessibility [duplicate]

Tags:

c#

list

Possible Duplicate:
Inconsistent accessibility

When I try returning a List<MyType> in one of my methods to something calling it from another class, it is giving me the following error:

Inconsistent accessibility: return type System.Collections.Generic.List<MyType> is less accessible than method MyMethod(string, string, string, string, string, string, string, string, string, string, string)

Any ideas on what to do here?

like image 784
user1314075 Avatar asked Sep 10 '12 02:09

user1314075


2 Answers

Well, pretty much just like it says. You probably have a List<SomeInternalClass> and you are returning that List<SomeInternalClass> from a PUBLIC method. So, the compiler is telling you that even though people can see this method, they CAN'T see the type you are trying to return. You will need to make your Method or your type both internal or both public.

Example:

internal class Foo {
}
public class Class1
{
    public List<Foo> Bar() {

    }
}
like image 62
aquinas Avatar answered Oct 21 '22 04:10

aquinas


This usually happens when your method is returning a generic list of MyType that is less accessible than the method returning it, for example

public class TestClass {
    public List<MyClass> MyMethod() {
        return new List<MyClass>();
    }
    private class MyClass {
        public string Name {get;set;}
    }
}
like image 28
Sergey Kalinichenko Avatar answered Oct 21 '22 03:10

Sergey Kalinichenko