Hi all. I am new to C#. I am getting a zero when a multiplication. Actually i am not able to pass a values to the class from the client, through the objeuct despite having a constructor. Below is the code.(I have excluded the Cube class since it is just okay. what is the problem is the cylinder class.) Please help.

using System;
public class Polygon //this is my base class.
{
	protected int length;
	protected int width;
	public Polygon(int length, int width)
	{
		this.length = length;
		this.width = width;
	}
	public Polygon(int length) // i created this constructor for the cyclinder class.
	{
		this.length = length;
	}
	public virtual void  FindArea() //Overridable function
	{
		int area = length * width;
		Console.WriteLine("The area is {0}",area);
	}
}
public class Cube : Polygon
{
      // .
      //.
      // .
      // This Class is working just fine.

}

public class Cylinder : Polygon
{
	private int radius;
	public Cylinder(int length,  int raduis) : base(length)
	{
		this.radius = radius;
	}
	public override void FindArea()
	{
		
		int area = (22/7) * radius * radius * length;
		Console.WriteLine("The area of the Cylinder is {0} {1} {2}",area,radius,length); // When i output the radius, it gives me a zero (0)      //and hence my result is zero!
	}

}


namespace Rectangle
{

	class Test
	{

	
		static void Main(string[] args)
		{
			Polygon[] PolyArray = new Polygon[3];
			PolyArray[0] = new Polygon(2,3);
			PolyArray[1] = new Cube(2,3,4);
			PolyArray[2] = new Cylinder(2,14);
			for(int i = 0; i<3 ; i++)
			{
				PolyArray[i].FindArea();
			}
			Cylinder Cyl = new Cylinder(2,14);
			Cyl.FindArea();// This is to output the result.
		}
	}
}

Because of this line : base(length)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.