- 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.
- iOS面試一戰到底
- 解構產品經理:互聯網產品策劃入門寶典
- CentOS 7 Linux Server Cookbook(Second Edition)
- Java程序員面試算法寶典
- Learning Apache Kafka(Second Edition)
- ADI DSP應用技術集錦
- Terraform:多云、混合云環境下實現基礎設施即代碼(第2版)
- Android應用開發實戰
- OpenCV 3.0 Computer Vision with Java
- Xamarin Cross-Platform Development Cookbook
- 基于JavaScript的WebGIS開發
- 系統分析師UML用例實戰
- Advanced C++
- 精通Django 3 Web開發
- C++程序設計基礎(下)