C# Online Compiler
Example: C# Program to Find Area of Rectangle using Constructor
C
C++
C#
Java
Python
PHP
main.cs
STDIN
Run
// C# Program to Find Area of Rectangle using Constructor using System; public class Rect { public float a, b; // It's the default constructor of the `Rect` class public Rect (float x, float y) { a=x; b=y; } // It will calculate the area of the rectangle public float Area() { return a * b; } } public class W3CW { // It's the driver function static public void Main (string[] args) { Console.WriteLine("Enter the length & width of the rectangle::\n"); float length=Convert.ToInt32(Console.ReadLine()); float width=Convert.ToInt32(Console.ReadLine()); // It will create the instance of the `Rect` class Rect RectObj = new Rect(length, width); // It will print the final output Console.WriteLine("Area of the rectangle is: "+RectObj.Area()+" units"); } }
9 8
Output
Clear
ADVERTISEMENTS