Resolved Cannot implicitly convert type 'void' to...

bondra

Well-known member
Joined
Oct 24, 2020
Messages
77
Programming Experience
Beginner
I just staring och scrolling upp and down with no ideas of how to proceed :mad:
I get following "Error CS0029 Cannot implicitly convert type 'void' to 'Joppes_hundar.Toy'".

There're a lot of posts of there but none seems to help me. I've left out code. Please let me know if further code is necessary.

Method Fetch:
           public static void Fetch()
            {
                   var selectedPet = (Animal)null;
                   var selectedToy = (Toy)null;

                   int input = int.Parse(Console.ReadLine());

                   Console.Write("\n Enter index for animal: ");
                   selectedPet = Petowner.Pets[input - 1];
                   selectedToy = selectedPet.GetToy(); // The line which gives an error
                    }
                }
            }


Toy class:
    abstract class Toy
    {
       // ..
    }

Animal class:
    abstract class Animal
    {
        public void GetToy()
        {
        // ...
        }
    }
 
Solution
Back
Top Bottom