Write a method called that takes two int parameters: width and height, and returns the area of a rectangle
Output should be like this

Write a method called that takes two int parameters: width and height, and returns the area of a rectangle
Output should be like this

Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sachin SinghRank #66 · 26.2K reputationPosted Mar 3, 2023, 10:29 AM EST
using System; public class Program { public static void Main(string[] args) { Console.WriteLine ("Enter Width"); int w=Convert.ToInt32(Console.ReadLine()); Console.WriteLine ("Enter Height"); int h=Convert.ToInt32(Console.ReadLine()); int area=w*h; Console.WriteLine ("Area for width {0} and Height {1} ss {2}",w,h,area); } }Naimish MakwanaRank #324 · 7.7K reputationPosted Mar 3, 2023, 11:04 AM EST
Hello Divyansha,
You can create program like below
using System; public class Program { public static void Main() { Console.Write("Enter width: "); int width = int.Parse(Console.ReadLine()); Console.Write("Enter height: "); int height = int.Parse(Console.ReadLine()); int area = CalculateRectangleArea(width, height); Console.WriteLine($"Area for width {width} and height {height} is {area}"); } public static int CalculateRectangleArea(int width, int height) { return area = width * height; } }Thanks
Naimish Makwana
Jignesh KumarRank #91 · 22.9K reputationPosted Mar 3, 2023, 10:22 AM EST
Public int CalculateArea(int length, int height) { return length * height; } // Call this method in main method Var area = CalculateArea(5,4);https://dotnettutorials.net/lesson/area-of-rectangle-in-csharp/