官术网_书友最值得收藏!

How to do it...

  1. Create a method called GetShopfloorSpace() that takes three parameters: for the common area space, the building width, and the building length.
        public Building GetShopfloorSpace(int floorCommonArea,
int buildingWidth, int buildingLength)
{

}
  1. We are returning a Building type, so create a class called Building that has a single property called TotalShopFloorSpace.
        public class Building
{
public int TotalShopFloorSpace { get; set; }
}
  1. Our local function will simply take the width and length of the building to calculate the total floor area and then subtract the common area from that to get the usable floor space for shops. The local function will look as follows:
        int CalculateShopFloorSpace(int common, int width, int length)
{
return (width * length) - common;
}
  1. This is where it gets interesting. Add the local function inside the GetShopfloorSpace() method and add the rest of the code in the following code example:
        public Building GetShopfloorSpace(int floorCommonArea,
int buildingWidth, int buildingLength)
{
Building building = new Building();

building.TotalShopFloorSpace = CalculateShopFloorSpace(
floorCommonArea, buildingWidth, buildingLength);

int CalculateShopFloorSpace(int common, int width, int length)
{
return (width * length) - common;
}

return building;
}
  1. In the calling code, inside the static void Main method, call the method as follows:
        Chapter1 ch1 = new Chapter1();
Building bldng = ch1.GetShopfloorSpace(200, 35, 100);
WriteLine($"The total space for shops is
{bldng.TotalShopFloorSpace} square meters");
  1. Run your console application and see the output displayed as follows:
主站蜘蛛池模板: 砀山县| 抚顺县| 保定市| 淮阳县| 益阳市| 房产| 正宁县| 广宁县| 黄大仙区| 韩城市| 阿图什市| 富阳市| 丽水市| 大荔县| 鄂托克旗| 延安市| 陆河县| 松原市| 百色市| 延吉市| 庆阳市| 江西省| 会宁县| 东乌珠穆沁旗| 平乡县| 平邑县| 古蔺县| 东城区| 崇明县| 湘潭市| 剑阁县| 长白| 辉南县| 芜湖市| 三门县| 兰西县| 新乐市| 井陉县| 文成县| 城市| 元谋县|