using System; using System.Collections.Generic; using System.Text; namespace 方法重载 { class area { public static double AREA(double r) { double pi = 3.14, j=0; j = r * r * pi; return j; } public static double AREA(double h,double l) { double j = 0; j = h*l; return j; } public static void AREA() { Console.WriteLine("请输入正方形的边长"); double b = 0, j = 0; b = Convert.ToDouble(Console.ReadLine()); j = b * b; Console.WriteLine("正方形的面积为{0}",j); } } }
using System; using System.Collections.Generic; using System.Text; namespace 方法重载 { class no_static { public double AREA(double r) { double pi = 3.14, j = 0; j = r * r * pi; return j; } public double AREA(double h, double l) { double j = 0; j = h * l; return j; } public void AREA() { Console.WriteLine("请输入正方形的边长"); double b = 0, j = 0; b = Convert.ToDouble(Console.ReadLine()); j = b * b; Console.WriteLine("正方形的面积为{0}", j); } } }
using System; namespace 方法重载 { class Program { static void Main(string[] args) { Console.WriteLine("Hello World!"); int i=0,o=0;double h = 0, k = 0; Console.WriteLine("请输入你要求图形的序号"); Console.WriteLine("1、圆形"); Console.WriteLine("2、长方形"); Console.WriteLine("3、正方形"); i = int.Parse(Console.ReadLine()); switch (i) { case 1: Console.WriteLine("请输入半径"); h =double.Parse(Console.ReadLine()); Console.WriteLine("圆形面积为:{0}",area.AREA(h) ); break; case 2: Console.WriteLine("请输入长和宽"); h = double.Parse(Console.ReadLine()); k = double.Parse(Console.ReadLine()); Console.WriteLine("长方形面积为:{0}", area.AREA(h, k));; break; case 3: area.AREA(); break; default: break; } Console.WriteLine("请输入你要求图形的序号"); Console.WriteLine("1、圆形"); Console.WriteLine("2、长方形"); Console.WriteLine("3、正方形"); o = int.Parse(Console.ReadLine()); switch (o) { case 1: Console.WriteLine("请输入半径"); h = double.Parse(Console.ReadLine()); no_static a = new no_static(); Console.WriteLine("圆形面积为:{0}", a.AREA(h)); break; case 2: Console.WriteLine("请输入长和宽"); h = double.Parse(Console.ReadLine()); k = double.Parse(Console.ReadLine()); no_static aa = new no_static(); Console.WriteLine("长方形面积为:{0}", aa.AREA(h, k)); ; break; case 3: no_static aaa = new no_static(); aaa.AREA(); break; default: break; } Console.ReadLine(); } } }
标签:Console,AREA,c#,double,static,WriteLine,重载,ReadLine From: https://www.cnblogs.com/bky-wang/p/18125078