Saturday, July 24, 2010

How to use object oriented concepts (classes and objects) in a asp.net web page - C# , Asp.net

    public partial class Test : Page
    {
        private Car car1, car2;
 
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            /// 
            /// new car object
            /// 
            car1 = new Car();
            /// 
            /// new car object with inline constructor
            /// 
            car2 = new Car()
            {
                Color = "Blue",
                Price = 45000,
                MaxSpeed = 200,
                Bhp = 300
            };
            /// 
            /// set properties
            /// 
            car1.Color = "Black";
            car1.Price = 25000;
 
        }
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            /// 
            /// Call methods
            /// 
            car1.Drive();
            car1.Reverse();
        }
        protected void Button_Clicked(object sender, EventHandler e)
        {
            /// 
            /// Call methods
            /// 
            car1.Drive();
            car1.Turn();
            car1.Drive();
            /// 
            /// Call methods
            /// 
            car2.Reverse();
            car2.Turn();
            car2.Drive();
            car2.Turn();
            car2.Drive();
        }
    }
    public class Car
    {
        /// <summary>
        /// Automatic Properties
        /// </summary>
        public string Color { getset; }
        public double Price { getset; }
        public int MaxSpeed { getset; }
        public int Bhp { getset; }
 
        /// <summary>
        /// Construcotrs
        /// </summary>
        public Car()
        {
            this.Color = "Red";
            this.Price = 30000;
            this.MaxSpeed = 140;
            this.Bhp = 335;
        }
 
        public void Drive()
        {
            ///
            /// Implement how to drive
            /// 
        }
        public void Reverse()
        {
            ///
            /// Implement how to reverse
            ///
        }
        public void Turn()
        {
            ///
            /// Implement how to turn
            ///
        }
    }

No comments:

Azure Storage Account Types

Defferent Types of Blobs Block blobs store text and binary data. Block blobs are made up of blocks of data that can be managed individually...