c#语法的例子

mac2022-06-30  27

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1121 {     class Rectangle     {         //成员变量         double length;         double width;         public void Acceptdetails() //显示length=4.5,wide=3.5         {             length = 4.5;             width = 3.5;         }         public double GetArea() //计算length*wide的数值         {             return length * width;         }         public void Display()   //一个用来打印的方法         {             Console.WriteLine("length:{0}", length);             Console.WriteLine("width:{0}", width);             Console.WriteLine("Area:{0}", GetArea());//打印GetArea方法的计算结果         }     }     class ExecuteRectangle     {         static void Main(string[] args)     //程序入口方法,创建实例,调用相应方法         {             Rectangle r = new Rectangle();//创建一个名称为r的实例             r.Acceptdetails();             //调用函数Acceptdetils给r赋值             r.Display();                   //调用函数Display打印结果             Console.ReadLine();         }     } }   逻辑: 1、进入main方法,创建明称为r的实例 2、调用Acceptdetils给r赋值 3、调用函数display打印结果     

转载于:https://www.cnblogs.com/heshaoqi/p/9996388.html

最新回复(0)