Thursday, 2 May 2013

How to set Width and height program in c#

How to set Width and height program in c#
Object


Write a class Rectangle having three fields Color, Width and height. User must be able to set and get these fields using properties.


Code


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

namespace ConsoleApplication1
{
    class rectangle
    {
        string color;
        double width;
        int height;
        public string rectanglecolor
        {
            set { color = value; }
            get { return color; }
        }
        public double rectanglewidth
        {
            set { width = value; }
            get { return width; }
        }
        public int rectangleheight
        {
            set { height = value; }
            get { return height; }
        }

    }

    class Program
    {
        static void Main(string[] args)
        {
            rectangle r = new rectangle();
            r.rectanglecolor = "blue";
            r.rectangleheight = 24;
            r.rectanglewidth = 34.33;
            Console.WriteLine(r.rectanglecolor);
            Console.WriteLine(r.rectangleheight);
            Console.WriteLine(r.rectanglewidth);
        }
    }
}


Screen Shot

No comments:

Post a Comment