"Go 맵 리터럴"의 두 판 사이의 차이

51번째 줄: 51번째 줄:
==같이 보기==
==같이 보기==
* [[Go 맵]]
* [[Go 맵]]
* [[Go 맵 변형하기]]
* [[Go 구조체 리터럴]]
* [[Go 구조체 리터럴]]
* [[리터럴]]
* [[리터럴]]

2020년 8월 6일 (목) 00:41 판

1 개요

Go Map literals
Go 맵 리터럴

2 예시 1

package main

import "fmt"

type Vertex struct {
	Lat, Long float64
}

var m = map[string]Vertex{
	"Bell Labs": Vertex{
		40.68433, -74.39967,
	},
	"Google": Vertex{
		37.42202, -122.08408,
	},
}

func main() {
	fmt.Println(m)
}

3 예시 2

  • 최상위 형(type)이 형 이름인 경우 리터럴 요소에서 생략할 수 있다.
package main

import "fmt"

type Vertex struct {
	Lat, Long float64
}

var m = map[string]Vertex{
	"Bell Labs": {40.68433, -74.39967},
	"Google":    {37.42202, -122.08408},
}

func main() {
	fmt.Println(m)
}

4 같이 보기

5 참고

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}