Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inconsistent accessibility: property type is less accessible

Tags:

c#

properties

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(); }
        }
    }
}
like image 953
David Bukera Avatar asked Dec 01 '12 14:12

David Bukera


3 Answers

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(); }
        }
    }
}
like image 177
Ravindra Bagale Avatar answered Nov 13 '22 06:11

Ravindra Bagale


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

like image 21
J. Steen Avatar answered Nov 13 '22 07:11

J. Steen


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.

like image 8
Lee Avatar answered Nov 13 '22 06:11

Lee