Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

C# : "Uccellino" does not contain a definition for "number"

given this two classes, a heap of objects, visual studio tells me that the class "Uccellino" has not property "number", how can I solve this? Thanks in advance to who will help me.

Minheap Class:

public class MinHeap<Uccellino>
    {
        Uccellino[] heap;
        int capacity;
        int occupied;

        //[...]

        public Uccellino  Parent(int index)
        {
            return heap[(index - 1) / 2];

        }

                public void Inserisci( Uccellino u)
        {
            heap[occupied] = u;
            int i = occupied;
            occupied++;

            while (i != 0 && ((Uccellino)Parent(i)).number > ((Uccellino)heap[i]).number) //it gives me error in this line
            {
                Uccellino temp = heap[i];
                heap[i] = Parent(i);
                heap[(i - 1) / 2] = temp;
                i = (i - 1) / 2;
            }
        }
    }

Uccellino class:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

public class Uccellino
    {
        public int id { get; }
        public int number { get; }

        public Uccellino(int identifier, int num)
        {
            this.id = identifier;
            this.number = num;
        }
    }

>Solution :

public class MinHeap<Uccellino> declares a generic class with generic type parameter with name Uccellino. Either remove it (it seems to not be needed here) or rename it to something like T, otherwise it shadows the Uccellino class:

public class MinHeap
{
   // the rest is the same
}

Read more:

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading