- C# 7 and .NET Core Cookbook
- Dirk Strauss
- 231字
- 2021-07-03 00:11:53
How to do it...
- 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)
{
}
- 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; }
}
- 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;
}
- 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;
}
- 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");
- Run your console application and see the output displayed as follows:

推薦閱讀
- Learning Real-time Processing with Spark Streaming
- Mastering JavaScript Object-Oriented Programming
- 算法基礎(chǔ):打開程序設(shè)計之門
- Learning Informatica PowerCenter 10.x(Second Edition)
- Scratch 3游戲與人工智能編程完全自學(xué)教程
- INSTANT CakePHP Starter
- 機械工程師Python編程:入門、實戰(zhàn)與進階
- Python自然語言處理(微課版)
- Scala編程實戰(zhàn)(原書第2版)
- 運用后端技術(shù)處理業(yè)務(wù)邏輯(藍橋杯軟件大賽培訓(xùn)教材-Java方向)
- Image Processing with ImageJ
- Learning Splunk Web Framework
- Vue.js光速入門及企業(yè)項目開發(fā)實戰(zhàn)
- JBoss AS 7 Development
- Flutter之旅