- 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.
- Android Wearable Programming
- JavaScript全程指南
- Python數(shù)據(jù)分析入門與實戰(zhàn)
- Visual C++實例精通
- Oracle 12c中文版數(shù)據(jù)庫管理、應用與開發(fā)實踐教程 (清華電腦學堂)
- Internet of Things with Intel Galileo
- Learning Vaadin 7(Second Edition)
- Unity 2D Game Development Cookbook
- Java高并發(fā)核心編程(卷1):NIO、Netty、Redis、ZooKeeper
- Java零基礎實戰(zhàn)
- JavaScript+jQuery網(wǎng)頁特效設計任務驅(qū)動教程
- Python計算機視覺和自然語言處理
- Data Science Algorithms in a Week
- Wearable:Tech Projects with the Raspberry Pi Zero
- Professional JavaScript