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

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.

主站蜘蛛池模板: 涿鹿县| 碌曲县| 广灵县| 璧山县| 小金县| 乐东| 绥德县| 富宁县| 宜城市| 长顺县| 县级市| 毕节市| 高青县| 黑龙江省| 连云港市| 双城市| 澄迈县| 上杭县| 西乌珠穆沁旗| 乌兰浩特市| 苍梧县| 铜鼓县| 类乌齐县| 松滋市| 巴里| 通榆县| 石楼县| 广饶县| 潢川县| 镇雄县| 牟定县| 天镇县| 淄博市| 平果县| 南宁市| 大竹县| 涿鹿县| 斗六市| 庆安县| 盘锦市| 治多县|