- Hands-On Object:Oriented Programming with C#
- Raihan Taher
- 173字
- 2021-07-02 12:44:41
Creating a method
Now that we know what a method is, let's take a look at an example, as shown in the following code:
public string GetFullName(string firstName, string lastName){
return firstName + lastName;
}
This code will create a method called GetFullName. This method takes two parameters, firstName and lastName, which are placed inside the parentheses. We can also see that we have to specify the types of those parameters. In this particular example, both the parameter types are string.
Now, take a look at the method body, which is the section between the curly brackets, {}. We can see that the code returns firstName + lastName, which means that it is concatenating the two parameters, firstName and lastName, and returning the string. As we are planning to return a string from this method, we set the return type of the method to string. Another thing to notice is that the access type is set to public for this method, which means that any other class can access it.
- Software Defined Networking with OpenFlow
- C語言程序設計(第2版)
- 算法精粹:經典計算機科學問題的Java實現
- Network Automation Cookbook
- 基于Java技術的Web應用開發
- Mastering Yii
- 人人都是網站分析師:從分析師的視角理解網站和解讀數據
- PySide GUI Application Development(Second Edition)
- Mastering React
- 軟件供應鏈安全:源代碼缺陷實例剖析
- SciPy Recipes
- 從零開始:UI圖標設計與制作(第3版)
- Struts 2.x權威指南
- Java程序性能優化實戰
- Mastering VMware Horizon 6