How to set Width and height program in c#

May 02, 2013

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

You Might Also Like

0 comments

Popular Posts

Like us on Facebook

Flickr Images