in virtute Dei in virtute Dei - 4 months ago 11
C# Question

How to Set up an Area method in a C# Program

Okay, so I have just started to learn the basic of coding in C# with Visual Studio 2015 and for the life of me I can not figure out how to set up an area method using Two Length and Width variables.
Here is a snippet from my code:

class RVent : Vent
private int w;

public RVent(double w, double l, String rn) : base (w, l,rn)
Width = w;
Length = l;
Roomname = rn;

//area method for a rectangle
//Area = l*w
public void area()

//double operator *(double w, double l);
area = (Length * Width);

I have searched Google and have visited forums and I am not able to grasp what I am doing wrong? Any help would be appreciated, Thank You.


area is a method. It's an action, you can't assign a value to it, you can just call it, and use the value it returns to you. Currently, your method signature says you aren't returning any value. You want to change your method to return a value that represents the area:

public double area()
    return Length * Width;

note that methods denote an action, so they are generally named with verbs. You'd call this method something like GetArea().