- Hands-On Object:Oriented Programming with C#
- Raihan Taher
- 192字
- 2021-07-02 12:44:41
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.
- 零基礎搭建量化投資系統:以Python為工具
- Android和PHP開發最佳實踐(第2版)
- 人臉識別原理及算法:動態人臉識別系統研究
- 基于Swift語言的iOS App 商業實戰教程
- Building Minecraft Server Modifications
- 名師講壇:Spring實戰開發(Redis+SpringDataJPA+SpringMVC+SpringSecurity)
- Learning Hunk
- bbPress Complete
- Maker基地嘉年華:玩轉樂動魔盒學Scratch
- R語言:邁向大數據之路(加強版)
- TypeScript圖形渲染實戰:2D架構設計與實現
- 程序員必會的40種算法
- Keil Cx51 V7.0單片機高級語言編程與μVision2應用實踐
- 關系數據庫與SQL Server 2012(第3版)
- 生成藝術:Processing視覺創意入門