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

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.

主站蜘蛛池模板: 齐齐哈尔市| 彰化市| 林西县| 德江县| 东丰县| 永新县| 江达县| 宁河县| 绥化市| 合山市| 延吉市| 老河口市| 青海省| 衢州市| 淅川县| 商丘市| 开封市| 伊川县| 满洲里市| 大安市| 综艺| 巴青县| 台前县| 台江县| 衡阳市| 清徐县| 云阳县| 青浦区| 山阳县| 鄂伦春自治旗| 凤阳县| 胶南市| 陵水| 定结县| 宁海县| 嘉黎县| 四子王旗| 祁阳县| 东海县| 宜宾县| 屯留县|