开发者

Accessibility of accessors error

I have the following line of code in my program

public Chromosome NewChromosome { get; public set; }

which gives the following error:

Error 1

The accessibility modifier of the 'ARP_TLL.DataAccess.ChromosomeAddedEventArgs.NewChromosome.set' accessor must be more restrictive than the property or indexer 'ARP_TLL.DataAccess.ChromosomeAddedEventArgs.NewChromosome'

C:\Users\kiangtengl\Programming\Projects\ARP_TLL\ARP_TLL\DataAccess\ChromosomeAddedEventArgs.cs

16

55

ARP_TLL

I have tried modifying the accessibility modifiers of the accessors and the property but I am unable to fix the problem.

开发者_开发百科

For reference, here is the type Chromosome

public class Chromosome
{
    #region properties

    public int Length
    {
        get;
        set;
    }

    public int Number
    {
        get;
        set;
    }

    #endregion

    #region creation

    public static Chromosome CreateChromosome(int _length, int _number)
    {
        return new Chromosome
        {
            Length = _length, Number = _number, 
        };
    }
    #endregion
}


Drop the public access modifier on the setter:

public Chromosome NewChromosome { get; set; }

By default, access modifiers for a property's accessors are assigned the same access modifier as the property itself. If you choose to set an explicit access modifier for an accessor, it must be more restrictive than the property's access modifier.


Remove public from public set or make it more restrictive than public. In

[property_access_modifier] property_type property_name {
    [get_accessor_modifier] get;
    [set_accessor_modifier] set;
}

it must be that get_accessor_modifier and set_accessor_modifier are more restrictive than property_access_modifier. In your case, property_access_modifier is public so that get_accessor_modifier and set_accessor_modifier must be protected, internal, protected internal or private.

Keep in mind that if property_access_modifier is omitted then it defaults to private and get_accessor_modifier and set_accessor_modifier default to property_access_modifier if they are omitted.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜