Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

invoking method 1

Status
Not open for further replies.

akaballa

Programmer
Feb 2, 2007
8
CA
Hi,

I keep getting an error message when I try to call the below methods and show output them in the console.WriteLine method. Please have a look:

using System;

namespace ConsoleApplication1
{
class Building
{
int floor;
int occupants;
int area;

public Building(int f, int o, int a)
{
floor = f;
occupants = o;
area = a;
}

public int areaPerPerson()
{
return area / occupants;
}

public int maxOccupants(int minArea)
{
return area / minArea;
}

}

class Test
{
public static void Main()
{
Building office = new Building(20, 1200, 15000);
Building house = new Building(3, 4, 1500);

Console.WriteLine("Each person in the office will be provided with an area of {0}", office.areaPerPerson);//problem here

Console.WriteLine("Each person in the house will be provided with an area of {0}", house.areaPerPerson); //problem here

Console.WriteLine("The maximum number of occupants in the office is {0}", office.maxOccupants(20));//problem here

Console.WriteLine("The maximum number of occupants in the office is {0}", house.maxOccupants(20));//problem here

}
}
}
 
I keep getting an error message when I try to call the below methods and show output them in the console.WriteLine method. Please have a look:

You don't say what error message you get!!

[vampire][bat]
 
sorry,

here is the message:

"Cannot convert method group 'areaPerPerson' to non-delegate type 'int'.
 
Try:

[tt]
Console.WriteLine("Each person in the office will be provided with an area of {0}", office.areaPerPerson());//problem here

Console.WriteLine("Each person in the house will be provided with an area of {0}", house.areaPerPerson()); //problem here
[/tt]


Hope this helps.

[vampire][bat]
 
By the way, I would add [tt]Console.ReadLine()[/tt] as a final line to keep the output on screen until you press enter.


Hope this helps.

[vampire][bat]
 
akaball,
Looks like a student question so you might want to learn how to find errors. A search engine is one way.
Cannot convert method group 'areaPerPerson' to non-delegate type 'int'.
all I did was google; Cannot convert method group to non-delegate type 'int', and the fourth result is
Compiler Error CS0428

"This error occurs when converting a method group to a non-delegate type, or attempting to invoke a method without using parentheses."

A star for earthandfire.

Marty
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top