Inconsistent accessibility: return type is less accessible than method

Hi folks,

I’m totally screwed about an error I cannot fix. And I definitely
don’t believe it’s my entire fault. So I created a little Safari Park for an easier
imagining of the issue.

But come on, let’s play. Once upon the time, there’s a
little Safari Park. It has lots of different Animals. You can feed them and
they will grow. If they are lucky they even make noises. Sometime the Safari
Park have to catch Animals, therefore some special skilled Catchers are hired. The
Park shows the Catcher all Animals and the Catcher decides on his own if and
how he catches the Animal. After the work is done, the Catcher gives you a cage
full of the desired Animals.

Sounds very easy so far, but I used generics to get the code
not only type-safe but also user safe. Now it looks much trickier:

 //SafariPark- – – – – – – – – – – – – – – – – – – – – – – – – –
namespace SafariPark
{
    public class SafariPark
    {
        IList la = new List();

        public SafariPark()
        {
            la.Add(new animals.Tiger(“Rocky”, animals.Sex.Male));
            la.Add(new animals.Tiger(“Lucy”, animals.Sex.Female));
        }

        public void hire(catcher.Catcher catcher){
            IEnumerator ea= la.GetEnumerator();
            while (ea.MoveNext())
                catcher.show(ea.Current);
        }
    }
}

//SafariPark.animals- – – – – – – – – – – – – – – – – – – – – –
namespace SafariPark.animals
{
    public struct Size
    {
        public int Height;
        public int Length;
    }

    public enum Sex { Male, Female }

    abstract public class Animal
    {

        protected string nm;
        protected Size sz;
        protected Sex sx;

        public string Name
        {
            get { return nm; }
        }
        public Size Size
        {
            get { return sz; }
        }
        public Sex Sex
        {
            get { return sx; }
        }

        protected Animal(string name, Size size, Sex sex)
        {
            this.nm = name;
            this.sz = size;
            this.sx = sex;
        }

        public void feed()
        {
            // and the animal grows if it’s still small 😉
            Size targetSize = growsTo();

            int oldHeight = sz.Height;
            int targetHeight = targetSize.Height;
            sz.Height = oldHeight * (1 + ((targetHeight – oldHeight) / targetHeight));

            int oldLength = sz.Length;
            int targetLength = targetSize.Length;
            sz.Length = oldLength * (1 + ((targetLength – oldLength) / targetLength));
        }

        public abstract Size growsTo();
        public abstract void makeNoise();
    }

    class Tiger : Animal
    {

        public Tiger(string name, Sex sex)
            : base(name, new Size(), sex)
        {
            sz.Height = 15;
            sz.Length = 25;
        }

        public override Size growsTo()
        {
            Size targetSize = new Size();
            targetSize.Height = 100;
            targetSize.Length = 145;
            return targetSize;
        }

        public override void makeNoise()
        {
            Console.WriteLine(“Meeow”);
        }
    }

    class Elephant:Animal
    {
        public Elephant(string name, Sex sex)
            : base(name, new Size(), sex)
        {
            sz.Height = 120;
            sz.Length = 160;
        }

        public override Size growsTo()
        {
            Size targetSize = new Size();
            targetSize.Height = 2500;
            targetSize.Length = 3200;
            return targetSize;
        }

        public override void makeNoise()
        {
            Console.WriteLine(“Trawtaw”);
            // By the way:
            // I’m absolutely clueless about spelling animal voices
        }
    }
}

//SafariPark.catcher- – – – – – – – – – – – – – – – – – – – – –
namespace SafariPark.catcher
{
    public class Cage where T : animals.Animal
    {
        private T[] animals;
        public T[] getAnimals()
        {
            return animals;
        }

        protected Cage(T[] animals)
        {
            this.animals = animals;
        }
    }

    public interface Catcher where T:animals.Animal
    {
        void show(animals.Animal animal);
        Cage hunt();
    }

    public class TigerCatcher : Catcher
    {
        private IList lt = new List();

        #region Catcher Members

        public void show(global::SafariPark.animals.Animal animal)
        {
            if (animal is animals.Tiger)
                lt.Add((animals.Tiger)animal);
        }

        public Cage hunt()
        {
            animals.Tiger[] tigers = new animals.Tiger[lt.Count];
            IEnumerator et = lt.GetEnumerator();
            int i = 0;
            while (et.MoveNext)
                tigers[i++] = et.Current;
            return new Cage(tigers);
        }

        #endregion
    }

    class Elephant:Animal
    {
        public Elephant(string name, Sex sex)
            : base(name, new Size(), sex)
        {
            sz.Height = 120;
            sz.Length = 160;
        }

        public override Size growsTo()
        {
            Size targetSize = new Size();
            targetSize.Height = 2500;
            targetSize.Length = 3200;
            return targetSize;
        }

        public override void makeNoise()
        {
            Console.WriteLine(“Trawrtaw”);
            // By the way:
            // I’m absolutely clueless about spelling animal voices
        }
    }
}

I hope you didn’t spend too much time on it. Here is the
error which bothers me:

Inconsistent accessibility: return type
‘SafariPark.catcher.Cage‘ is less accessible
than method ‘SafariPark.catcher.TigerCatcher.hunt()’

Visual Studio points at the method hunt in the class TigerCatcher.
I think I’ve done any possibility to figure out where there error comes from
and how to fix it. But without any success! Who can help me?

I changed the following:

You need to make your Tiger class  public.  It is private now.

Thank you very much.The main issue  was the missing public  statement at class  Tiger and Elephant. The other errors within my weird code  popped up after fixing that. It’s very clear, now.Happy holidays to all helpers.Marcel