Inconsistent accessibility: property type is less accessible

后端 未结 3 1226
没有蜡笔的小新
没有蜡笔的小新 2020-12-14 05:34

Please can someone help with the following error:

Inconsistent accessibility: property type \'Test.Delivery\' is less accessible than property \'Test.

相关标签:
3条回答
  • 2020-12-14 05:40

    Your class Delivery has no access modifier, which means it defaults to internal. If you then try to expose a property of that type as public, it won't work. Your type (class) needs to have the same, or higher access as your property.

    More about access modifiers: http://msdn.microsoft.com/en-us/library/ms173121.aspx

    0 讨论(0)
  • 2020-12-14 05:42

    make your class public access modifier,

    just add public keyword infront of your class name

     namespace Test
    {
      public  class Delivery
        {
            private string name;
            private string address;
            private DateTime arrivalTime;
    
            public string Name
            {
                get { return name; }
                set { name = value; }
            }
    
            public string Address
            {
                get { return address; }
                set { address = value; }
            }
    
            public DateTime ArrivlaTime
            {
                get { return arrivalTime; }
                set { arrivalTime = value; }
            }
    
            public string ToString()
            {
                { return name + address + arrivalTime.ToString(); }
            }
        }
    }
    
    0 讨论(0)
  • 2020-12-14 05:53

    Your Delivery class is internal (the default visibility for classes), however the property (and presumably the containing class) are public, so the property is more accessible than the Delivery class. You need to either make Delivery public, or restrict the visibility of the thelivery property.

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