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

Methods in a class

Let's talk about another important topic—namely methods. A method is a piece of code that is written in the code file and can be reused. A method can hold many lines of code, which will be executed when it is called. Let's take a look at the general form of a method:

access-modifier return-type method-name(parameter-list) {
// method body
}

We can see that the first thing in the method declaration is an access-modifier. This will set the access permission of the method. Then, we have the return-type of the method, which will hold the type that the method will return, such as string, int, double, or another type. After that, we have the method-name and then brackets, (), which indicate that it is a method. In the brackets, we have the parameter-list. This can either be empty or can contain one or more parameters. Finally, we have curly brackets, {}, which hold the method body. The code that the method will execute goes inside here.

Any code following this structure will be considered a method by the C# compiler.

主站蜘蛛池模板: 丹巴县| 辰溪县| 白山市| 桂东县| 扶余县| 德钦县| 玉屏| 兰州市| 台南县| 三原县| 永城市| 车致| 石棉县| 靖宇县| 武夷山市| 青龙| 鲁山县| 双峰县| 安顺市| 隆林| 溧阳市| 来宾市| 思茅市| 静宁县| 文化| 清河县| 丰城市| 宜兴市| 平昌县| 武宣县| 醴陵市| 宜昌市| 额济纳旗| 花莲县| 新乡县| 安达市| 凉城县| 广汉市| 石渠县| 南丰县| 旬邑县|