Let's Go Together (ix)

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Functions in the Go language

Finally the turn function, actually also has nothing to say, is nothing but a grammar problem, C language has C language syntax, C # has C # syntax, then the function of Go language? In the previous article

In fact, we have seen some simple functions, and today we will look at the details, so please look at the following:

In the above code, we declare and define a total of two functions, one is say, the other is an anonymous function, and here, through the anonymous function, a function closure is generated. In the Go language

Declare a function with the Func keyword. So, if you want to declare a function, immediately think of Func, whether it's anonymous or not, the only difference is that there is no function name behind the anonymous function, directly

Func (parameter list) (return value). As we can see from the above, the return type of the Go language function is followed by the function name, and it is the same as the type that declares the variable, which is also different from most languages. And the return value of a function can be one or more. For example, the say function above, we return two, an integer type, an error. Where the integer type is the length of the variable parameter, the error type is one of the values returned from the printf function in the FMT package, and we see that the FMT is accepted. The first variable of the value returned by the Printf () function We use the "_" symbol, which means that we do not care about the first return value and ignore it. Then look at the second parameter of the Say function, is a ... interface{} type, three points is a type of go language slices, similar to an array, but different, this will continue to be described in subsequent articles, since it is a similar array of types, It can also be thought that a mutable parameter can receive any number, but must be of the same type, where an empty interface type is used as the element type of the slices, which allows the element to receive any type of argument, and then the actual type of each element can be inferred by default parameters.

author: Sirk   
source: http:// Www.cnblogs.com/vimsk

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.