C#返回列表-不一致的可访问性 [英] C# Returning List - Inconsistent Accessibility

查看:81
本文介绍了C#返回列表-不一致的可访问性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
可访问性不一致

Possible Duplicate:
Inconsistent accessibility

当我尝试将其中一个方法中的List<MyType>返回给从另一个类调用它的东西时,它给了我以下错误:

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:

可访问性不一致:返回类型System.Collections.Generic.List<MyType>的访问性比方法MyMethod(string, string, string, string, string, string, string, string, string, string, string)

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?

推荐答案

嗯,就像它说的那样.您可能有一个List<SomeInternalClass>,并且正在从 PUBLIC 方法返回该List<SomeInternalClass>.因此,编译器告诉您,即使人们可以看到此方法,他们也看不到您尝试返回的类型.您将需要公开您的方法或您的方法或内部的类型.

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.

示例:

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

    }
}

这篇关于C#返回列表-不一致的可访问性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆