© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
11 replies
Pilathien

Inconsistent accessibility: property type 'Exercises.Register.Gender' is less accessible than proper

I honestly have no clue how it's having issues with accessibility when both classes are within the same namespace and Dog.cs has no issue interacting with Gender enum in the exact same way.

Animal.cs
namespace Exercises.Register
{
    public abstract class Animal
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public string Breed { get; set; }
        public DateTime BirthDate { get; set; }
        public Gender Gender { get; set; }
        public DateTime LastVaccinationDate { get; set; }
        public int Age
        {
            get
            {
                DateTime today = DateTime.Today;
                int age = today.Year - this.BirthDate.Year;
                if (this.BirthDate.Date > today.AddYears(-age))
                {
                    age--;
                }
                return age;
            }
        }
        public abstract bool RequiresVaccination { get; }
        public Animal(int id, string name, string breed, DateTime birthDate, Gender gender)
        {
            this.ID = id;
            this.Name = name;
            this.Breed = breed;
            this.BirthDate = birthDate;
            this.Gender = gender;
        }
        public override bool Equals(object other)
        {
            return this.ID == ((Animal)other).ID;
        }
        public override int GetHashCode()
        {
            return this.ID.GetHashCode();
        }
        public int CompareTo(Animal other)
        {
            int result = this.Breed.CompareTo(other.Breed);
            if (result == 0)
            {
                return this.Gender.CompareTo(other.Gender);
            }
            return result;
        }
    }
}
namespace Exercises.Register
{
    public abstract class Animal
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public string Breed { get; set; }
        public DateTime BirthDate { get; set; }
        public Gender Gender { get; set; }
        public DateTime LastVaccinationDate { get; set; }
        public int Age
        {
            get
            {
                DateTime today = DateTime.Today;
                int age = today.Year - this.BirthDate.Year;
                if (this.BirthDate.Date > today.AddYears(-age))
                {
                    age--;
                }
                return age;
            }
        }
        public abstract bool RequiresVaccination { get; }
        public Animal(int id, string name, string breed, DateTime birthDate, Gender gender)
        {
            this.ID = id;
            this.Name = name;
            this.Breed = breed;
            this.BirthDate = birthDate;
            this.Gender = gender;
        }
        public override bool Equals(object other)
        {
            return this.ID == ((Animal)other).ID;
        }
        public override int GetHashCode()
        {
            return this.ID.GetHashCode();
        }
        public int CompareTo(Animal other)
        {
            int result = this.Breed.CompareTo(other.Breed);
            if (result == 0)
            {
                return this.Gender.CompareTo(other.Gender);
            }
            return result;
        }
    }
}


Gender.cs
namespace Exercises.Register
{
    enum Gender
    {
        Male = 1,
        Female = 2,
    }
}
namespace Exercises.Register
{
    enum Gender
    {
        Male = 1,
        Female = 2,
    }
}
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

✅ Inconsistent accessibility: property type is less accessible than property.
C#CC# / help
2y ago
Error: Inconsistent accessibility: property type 'type' is less accessible than property 'property'
C#CC# / help
3y ago
✅ Inconsistent accessibility: parameter type ''x" is less accessible than "y"
C#CC# / help
11mo ago
less accessible??
C#CC# / help
4y ago