开发者

C# - unable to return List

开发者 https://www.devze.com 2023-02-14 02:18 出处:网络
i\'m trying to return list of objects from a class and get the following error: Error1Inconsistent accessibility: property type \'System.Collections.Generic.List<EventXmlExtract.Attribute>\' is

i'm trying to return list of objects from a class and get the following error:

Error 1 Inconsistent accessibility: property type 'System.Collections.Generic.List<EventXmlExtract.Attribute>' is less accessible than property 'EventXmlExtract.EventExtract.AttributeList' C:\Documents and Set开发者_如何学编程tings\eyalk\My Documents\Visual Studio 2010\Projects\Blobs\EventExtractDll\EventExtract.cs 14 32 EventExtractDll

my code tries return _attributeList:

public class EventExtract
{
    private string _type;
    private int _type_id;
    private List<Attribute> _attributeList = new List<Attribute>();

    internal List<Attribute> AttributeList
    {
        get { return _attributeList; }
        set { _attributeList = value; }
    }
}

what is the problem ? and how can i retrieve the list ?


Make the class Attribute public or internal.

You can't return a list of objects where the class is private, because then the calling code can't access the objects.

Alternatively make the AttributeList as restricted as the Attribute class, if that is how you want it.


Your Attribute class lacks the required visibility.

change the class definition to either

public class Attribute
{

or

internal class Attribute 
{


I think the problem is that you have declared the property as private. Try making it as protected or public.


Did you include the following?

using System; using System.Collections.Generic;

The class compiles fine on my box... :)

0

精彩评论

暂无评论...
验证码 换一张
取 消