How to use Inheritance and constructor to pass variables correctly?
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace My_program { class Program { static void Main(string[] args) { House h = new House(1, 300, 5); h.About(); } } class Building { #region Variables //Buildings can be placed at diferent loacations protected int Location { get; set; } //Cost to build it protected int Cost { get; set; } #endregion protected Building(int Location, int Cost) { this.Location = Location; this.Cost = Cost; //This line is executed not as intended. Why Cost becomes 1? Console.WriteLine("Building in squere {0}, costing {0}, has been built!", Location, Cost); } public void About() { //Here everything is fine Console.Write("Building is placed in squere {0}, and cost {1} ", Location, Cost); } } class House : Building { //Inhabitants of the building private int People; //Building a house public House(int Location, int Cost, int People) : base(Location, Cost) { this.People = People; Console.WriteLine("House has {0} people living here", People); } } }