?
Solved

Cannot convert method group 'eat' to non-delegate type 'string'. Did you intend to invoke the method?

Posted on 2009-07-07
3
Medium Priority
?
1,679 Views
Last Modified: 2012-08-14
What is wrong?


Error Message:
Error      1      Cannot convert method group 'eat' to non-delegate type 'string'. Did you intend to invoke the method?      C:\Documents and Settings\MFL\Dokumenter\Visual Studio 2008\Projects\Animal_Park\Animal_Park\Animal.cs      342      31      Animal_Park

private void mealButton_Click(object sender, EventArgs e)
        {
            int i = mealComboBox.SelectedIndex;
            MealLabel.Text =  animalManager.AnimalList[i].eat;
        }
 
 
----------------------------------
AnimalManager
----------------------------------
 
public class AnimalManager
    {
        [XmlAttribute]
        private int count = 0;
        private List<Animal> animalList = new List<Animal>();     
 
 
 
--------------------------------------------
Animal
----------------------------------------------
 
 
        /// <summary>
        /// Eat method
        /// </summary>
        /// <param name="food"></param>
        /// <returns></returns>
        public virtual string eat(string food)
        {
            return "Animal eat method";
        }
 
--------------------------------------
PlantEater
------------------------------------
 /// <summary>
        /// Does it like it? Eat method
        /// </summary>
        /// <param name="food"></param>
        /// <returns></returns>
        public override String eat(string food)
        {
            foreach (string eat in likes)
            {
                if (eat.ToLower() == food.ToLower())
                {
                    return "Yummy";
                } //end if
            } //end foreach
 
            return "Uuuusccccccch";
        } //end eat

Open in new window

0
Comment
Question by:Mickeys
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
Pablissimo earned 2000 total points
ID: 24794303
private void mealButton_Click(object sender, EventArgs e)
        {
            int i = mealComboBox.SelectedIndex;
            MealLabel.Text =  animalManager.AnimalList[i].eat;
        }


needs to be

private void mealButton_Click(object sender, EventArgs e)
        {
            int i = mealComboBox.SelectedIndex;
            MealLabel.Text =  animalManager.AnimalList[i].eat();
        }


Parentheses after the eat - it's a method call.
0
 
LVL 5

Assisted Solution

by:Pablissimo
Pablissimo earned 2000 total points
ID: 24794309
Actually that's not quite right either - I'm not quite sure what you're trying to achieve but the following:
MealLabel.Text =  animalManager.AnimalList[i].eat( "Some food" );

Would work as an example. Something seems confused in the code though
0
 

Author Closing Comment

by:Mickeys
ID: 31600589
Thx. Been sitting to long today....so I got a bit blind. Of course you are right. I didnt see I should have something in and I forgot the ( ). Here is a working function: :-)

private void mealButton_Click(object sender, EventArgs e)
        {
            Int32 selected = AnimalDataGridView.CurrentRow.Index;
            MealLabel.Text = animalManager.AnimalList[selected].eat(mealComboBox.SelectedItem.ToString());
        }
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question