1. 用于数组: 表示长度与元素个数相同.

在golang中数组的长度是类型的一部分,不同长度,不同类型.

2. 用于参数: 用于形参表示可变参数. 用于实参表示直接传递. 具体解释参数见官方文档:

传递可变参数时:

(1) 如果实参后不跟..., 则在底层创建与形参类型相同的slice,然后将实参赋值后传递.

(2) 如果实参后跟..., 则不在底层创建与形参类型相同的slice,而是直接将实参传递给形参.

/ref/spec#Passing_arguments_to_..._parameters

Passing arguments to ... parameters

If f is variadic with a final parameter p of type ...T, then within f the type of p is equivalent to type []T. If f is invoked with no actual arguments for p, the value passed to p is nil. Otherwise, the value passed is a new slice of type []T with a new underlying array whose successive elements are the actual arguments, which all must be assignable to T. The length and capacity of the slice is therefore the number of arguments bound to p and may differ for each call site.

Given the function and calls

func Greeting(prefix string, who ...string)
Greeting("nobody")
Greeting("hello:", "Joe", "Anna", "Eileen")

within Greeting, who will have the value nil in the first call, and []string{"Joe", "Anna", "Eileen"} in the second.

If the final argument is assignable to a slice type []T, it may be passed unchanged as the value for a ...T parameter if the argument is followed by .... In this case no new slice is created.

Given the slice s and call

s := []string{"James", "Jasmine"}Greeting("goodbye:", s...)

within Greeting, who will have the same value as s with the same underlying array.

golang的"..."备忘的更多相关文章

  1. Ubuntu 16.04 下简单安装使用golang之备忘

      刚开始学习Go语言,这里记录下我在Ubuntu 16.04下安装使用golang的过程,方便以后查询.   一.安装   1.添加源   如果使用默认的源安装golang的话,版本太低,只到1.6 ...

  2. GIS部分理论知识备忘随笔

    文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/ 1.高斯克吕格投影带换算 某坐标的经度为112度,其投影的6度带和3度带 ...

  3. python序列,字典备忘

    初识python备忘: 序列:列表,字符串,元组len(d),d[id],del d[id],data in d函数:cmp(x,y),len(seq),list(seq)根据字符串创建列表,max( ...

  4. Vi命令备忘

    备忘 Ctrl+u:向文件首翻半屏: Ctrl+d:向文件尾翻半屏: Ctrl+f:向文件尾翻一屏: Ctrl+b:向文件首翻一屏: Esc:从编辑模式切换到命令模式: ZZ:命令模式下保存当前文件所 ...

  5. ExtJs4常用配置方法备忘

    viewport布局常用属性 new Ext.Viewport({ layout: "border", renderTo: Ext.getBody(), defaults: { b ...

  6. [备忘] Automatically reset Windows Update components

    这两天遇到Windows 10的更新问题,官方有一个小工具,可以用来修复Windows Update的问题,备忘如下 https://support.microsoft.com/en-us/kb/97 ...

  7. ECMAScript 5(ES5)中bind方法简介备忘

    一直以来对和this有关的东西模糊不清,譬如call.apply等等.这次看到一个和bind有关的笔试题,故记此文以备忘. bind和call以及apply一样,都是可以改变上下文的this指向的.不 ...

  8. MFC通过txt查找文件并进行复制-备忘

    MFC基于对话框的Demo txt中每行一个23位的卡号. 文件夹中包含以卡号命名的图像文件.(fpt或者bmp文件) 要求遍历文件夹,找到txt中卡号所对应的图像文件,并复制出来. VC6.0写的. ...

  9. php 相关模块备忘

    在安装php的时候,不管是编译安装: ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc -- ...

随机推荐

  1. C# 枚举显示中文

    转自:http://www.cnblogs.com/yank/archive/2011/09/08/EnumDisplayInChinese.html   using System; using Sy ...

  2. 既约分数-phi

    Description 小明正在学习分数这一章,他想知道对于一个真分数b/a而言,当分母a在[2,N]之间时,存在多少个既约分数,例如当N=4时,有以下几个1/2,1/3,1/4,2/3,3/4这五个 ...

  3. 图的强连通分量-Kosaraju算法

    输入一个有向图,计算每个节点所在强连通分量的编号,输出强连通分量的个数 #include<iostream> #include<cstring> #include<vec ...

  4. linx 实用操作命令二

    pcre相关操作pcretest -C #查看pcre是否支持utf8 rpm -q -a #查看软件包列表rpm -ql pcre-7.8-6.el6.x86_64 #查看包安装的位置rpm -e ...

  5. Response.Write页面跳转

    一.<a>标签 <a href=”test.aspx”></a> 这是最常见的一种转向方法 二.HyperLink控件   1. Asp.net 服务器端控件 属性 ...

  6. 二模11day2解题报告

    T1.修改文章(amend) 给出n个单词和一个长度为m的字符串,求改动多少个字符才能使字符串全由单词组成. 要说这道题还真的坑很坑超坑非常坑无敌坑--不过还是先想到了动规.毕竟要修改的前提是要组成的 ...

  7. docker1.12 安装pxc(Percona XtraDB Cluster )测试

    docker1.12 安装pxc(Percona XtraDB Cluster )测试

  8. C/C++中产生随机数

    可以使用srand()函数和rand()函数来产生随机数,其中srand()用来初始化随机数种子,rand()用来产生随机数.因为默认情况下随机数种子为1,而相同的随机数种子产生的随机数是一样的,失去 ...

  9. Servlet小试

    Java响应Http请求: 1.创建项目 因为对Java环境不是很熟悉,第一步卡住了好长时间, javax怎么引用, 在Java EE 5 Libraries中的javaee.jar中,项目中怎么引用 ...

  10. Linux下切换用户

    0x01 使用命令[su username] 这种方法能切换普通用户和root用户 0x02 从普通用户切换到root用户,还可以使用命令[sudo su] 0x03 su 是switch user的 ...