Solved

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

Posted on 2009-07-07
3
1,600 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
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
Pablissimo earned 500 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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

919 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now