How to use multi-parameter attribute parameters in Golang

Source: Internet
Author: User
This is a created article in which the information may have evolved or changed.

We often have headaches due to the uncertainty of incoming parameters, and Golang provides us with access to multivalued parameters to solve this problem. But generally we write the known code directly that all the values know that one is plugged in, but most of us are getting a lot of input from the user to pass through the loop, but this finds that the function of the multivalued parameter cannot be used. In fact, the underlying implementation treats multiple parameters as an array of indefinite lengths passed in. Then we have the idea: since the underlying use of arrays, then we can pass in the array, the conclusion is not possible, or it is reasonable to say: The array can not be directly passed in, need to assist multi-parameter identification to indicate, specifically let us look at the following a simple test:

Func Testmultiparam (t *testing. T) {    ValueArray: = []string{"1", "2", "3", "4", "5"}    Result: = Valuearray[0:3]    t.Log (result)    Multiparam (Result ...)  Here is the}func multiparam (args ... string) {    print (args)} that we normally need to use

So, it is possible to pass in an array, except that it needs to be followed by a "3 point" to represent an array of multiple arguments, so that there is no type exception at the receiving end.

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.