Inconsistent accessibility: property type is less accessible

C#Properties

C# Problem Overview


Please can someone help with the following error:

>Inconsistent accessibility: property type 'Test.Delivery' is less accessible than property 'Test.Form1.thelivery'

private Delivery thedelivery;

public Delivery thedelivery
{
    get { return thedelivery; }
    set { thedelivery = value; }
}

I'm not able to run the program due to the error message of inconsistency.

Here is my delivery class:

namespace Test
{
    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(); }
        }
    }
}

C# Solutions


Solution 1 - C#

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(); }
        }
    }
}

Solution 2 - C#

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

Solution 3 - C#

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDavid BukeraView Question on Stackoverflow
Solution 1 - C#Ravindra BagaleView Answer on Stackoverflow
Solution 2 - C#J. SteenView Answer on Stackoverflow
Solution 3 - C#LeeView Answer on Stackoverflow