加载中…
个人资料
丿灬草卩s祭巛
丿灬草卩s祭巛
  • 博客等级:
  • 博客积分:0
  • 博客访问:1,169
  • 关注人气:46
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

C# 简单矩形类

(2011-03-28 15:56:44)
标签:

c

无参

有参

矩形类

周长

面积

it

分类: 信息技术

C# 简单矩形类

实现要求:编写一个矩形类,私有数据成员为举行的长(len)和宽(wid),无参构造函数将len和wid设置为0,有参构造函数设置和的值,类包括属性:Len和Wid,分别为矩形的长和宽;类的共有方法有:求周长、求面积。

我的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication3
{
    class Rectangle
    {

        private int Len;
        private int Wid;

        public Rectangle()
        {
            Len = 0;
            Wid = 0;
        }
        public Rectangle(int len, int wid)
        {
            Len = len;
            Wid = wid;
        }

        public int Width
        {
            get { return Wid; }
            set { Wid = value; }
        }

        public int Lenth
        {
            get { return Len; }
            set { Len = value; }
        }

        public int Perimeter
        {
            get { return (Width + Lenth) * 2; }
        }

        public int Area
        {
            get { return Width* Lenth; }
             

    }

    class program
    {
        static void Main(string[] args)
        {
            Rectangle rectangle = new Rectangle(10,5);
            Console.WriteLine(rectangle.Width);
            Console.WriteLine(rectangle.Lenth);
            Console.WriteLine(rectangle.Area);
            Console.WriteLine(rectangle.Perimeter);
            Console.Read();

        }
    }
}
编程总结:暂无。

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有