c#基本语法

    xiaoxiao2021-12-14  20

    c#是一个面向对象的编程语言,在面向对象的程序设计方法中,程序由各种相互交互的对象组成,相同种类的对象通常具有相同的类型,或者说,是在相同的class中

    例如,以Rectangle矩形对象为例,他具有length和width属性,根据设计,他可能需要接受这些属性值,计算面积和显示细节

    using System;

    namespace RectangleApplication

    {

    class Rectangle

    {

    //成员变量

    double length;

    double width;

    public void Acceptdetails()

    {

    length=4.5;

    width=3.5;

    }

    public double GetArea()

    {

    return length*width;

    }

    public void Display()

    {

    Console.WriteLine("Length:{0}",length);

    Console.WriteLine("Width:{0}",width);

    Console.WriteLine("Area:{0}",GetArea());

    }

    }

    class ExecuteRectangle

    {

    static void Main(string[] args)

    {

    Rectangle r=new Rectangle();

    r.Acceptdetails();

    r.Display();

    Console.ReadLine();

    }

    }

    }

    转载请注明原文地址: https://ju.6miu.com/read-963049.html

    最新回复(0)