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

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.

主站蜘蛛池模板: 榆林市| 巴林右旗| 屯昌县| 龙口市| 桑日县| 正安县| 勐海县| 惠安县| 五大连池市| 东丰县| 莱州市| 河北区| 洛宁县| 三台县| 远安县| 剑阁县| 普宁市| 新安县| 海安县| 中西区| 昔阳县| 若尔盖县| 中阳县| 南充市| 兴城市| 长岛县| 沐川县| 兴业县| 浪卡子县| 嫩江县| 峡江县| 泾川县| 惠安县| 五台县| 民丰县| 西华县| 凯里市| 吴堡县| 平山县| 玛沁县| 灵宝市|