Results 1 to 2 of 2
  1. #1
    MaGx's Avatar
    Join Date
    Dec 2015
    Gender
    male
    Posts
    5
    Reputation
    10
    Thanks
    0

    What is the use of this ?

    Hello , I am learning c# currently .. I was looking for some sources on internet to learn and so I found this code , I understand everything but this part :

    public Calculator(double l, double w) : base(l, w) { }

    /// base.Display();

    What is base ? Just explain me how and why is base created .. I really don't understand !

    Here's my code :

    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace InheritanceApplication
    {
        class Rectangle
        {
            protected double length;
            protected double width;
    
            public Rectangle(double l, double w) 
            {
                length = l;
                width = w;
            }
    
            public double GetArea()
            {
                return width * length;
            }
            public void Display()
            {
                Console.WriteLine("Length: {0}", length);
                Console.WriteLine("Width: {0}", width);
                Console.WriteLine("Area: {0}", GetArea());
            }
        }
    
        class Calculator : Rectangle
        {
        
            public Calculator(double l, double w) : base(l, w) { }
            public double GetCost()
            {
                double cost;
                cost = GetArea() *50;
                return cost;
            }
            public void Display()
            {
                base.Display();
                Console.WriteLine("Cost: {0}", GetCost());
            }
    
        }
    
        class Execute
        { 
        
            static void Main()
            {
                Calculator kenny = new Calculator(2.5, 3.5);
                kenny.Display();
            }
        }
    }
    Thank you vm for your time

  2. #2
    Biesi's Avatar
    Join Date
    Dec 2011
    Gender
    male
    Posts
    4,993
    Reputation
    374
    Thanks
    8,808
    My Mood
    Twisted
    Your Calculator class inherits from the Rectangle class. The base keyword is used to access the underlying Rectangle class members. While the this keyword represents the current instance of your Calculator class.

    Inheritance (C# Programming Guide)
    Last edited by Biesi; 03-11-2016 at 07:36 AM.

Similar Threads

  1. Replies: 1
    Last Post: 03-11-2015, 11:46 PM
  2. [SOLVED] What is the name of this?
    By thatswhatsup77 in forum Call of Duty Modern Warfare 2 Help
    Replies: 5
    Last Post: 09-09-2010, 10:27 AM
  3. Apologies for being so stupid... but what's the name of this certain hack!
    By FallenLegacy in forum Combat Arms EU Discussions
    Replies: 20
    Last Post: 04-13-2010, 05:54 AM
  4. GRRRRRR!! what is the name of this song!!!???
    By dibiase in forum General
    Replies: 6
    Last Post: 07-14-2009, 09:05 AM