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

  • C# 7 and .NET Core Cookbook
  • Dirk Strauss
  • 231字
  • 2021-07-03 00:11:53

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:
主站蜘蛛池模板: 茌平县| 临夏县| 宁阳县| 萨嘎县| 延长县| 临沧市| 吉林省| 和林格尔县| 潜山县| 泰州市| 海淀区| 华池县| 新邵县| 缙云县| 乐亭县| 临夏县| 正阳县| 深泽县| 虹口区| 宜宾县| 正定县| 肥乡县| 青浦区| 会昌县| 饶平县| 云南省| 于田县| 盘锦市| 象山县| 新干县| 南靖县| 桃园市| 岳普湖县| 太谷县| 蒲城县| 龙里县| 晋城| 辛集市| 女性| 灌阳县| 姜堰市|