加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

golang 匿名函数用法

发布时间:2020-12-16 18:17:35 所属栏目:大数据 来源:网络整理
导读:// http://studygolang.com/articles/3756package mainimport ("fmt")func main() {c := func() int {fmt.Printf("func 1n")return 555555}fmt.Println(c)ww := c()fmt.Println(ww)func(arge int) {fmt.Printf("func %dn",arge)}(2)a := func() int {fmt.P
// http://studygolang.com/articles/3756
package main

import (
	"fmt"
)

func main() {
	c := func() int {
		fmt.Printf("func 1n")
		return 555555
	}
	fmt.Println(c)
	ww := c()
	fmt.Println(ww)

	func(arge int) {
		fmt.Printf("func %dn",arge)
	}(2)

	a := func() int {
		fmt.Printf("func 3n")
		return 666666
	}
	d := a()
	fmt.Println(d)

	fmt.Println("------------------------")

	var j int = 5
	k := func() func() { //返回函数指针
		var i int = 10
		return func() {
			fmt.Printf("i,j:%d,%dn",i,j)
		}
	}()
	fmt.Println(k)
	k()
	j *= 2
	k()

}

C:/Go/bin/go.exe build -i [F:/Go/src/gofunctest]

成功: 进程退出代码 0.

F:/Go/src/gofunctest/gofunctest.exe [F:/Go/src/gofunctest]

0x401330

func 1

555555

func 2

func 3

666666

------------------------

0x401500

i,j:10,5

i,10

成功: 进程退出代码 0.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读