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

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.

主站蜘蛛池模板: 侯马市| 渭源县| 阿图什市| 罗甸县| 运城市| 呼和浩特市| 临夏市| 海兴县| 佳木斯市| 来宾市| 榕江县| 贵定县| 石棉县| 祥云县| 新竹市| 普安县| 临潭县| 旺苍县| 利川市| 封丘县| 四会市| 宿州市| 灌南县| 鄂托克旗| 方山县| 红河县| 仁寿县| 扶沟县| 古田县| 高淳县| 汝南县| 张家港市| 怀仁县| 思南县| 武川县| 来凤县| 阿勒泰市| 临邑县| 商都县| 玛多县| 新丰县|