Go structs, slices, maps

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

"Go structs, slices, maps"

1, when defined * After the variable name, when used * in front of the variable name.

  

  

2, the definition struct,type before, the struct keyword after.

  

3. The pointer can specify a struct.

  

4, a struct literal denotes a newly allocated struct value by listing the values of their fields.

You can list just a subset of fields by using the Name: syntax. (and the order of named fields is irrelevant.)

  

5, the array definition.

  

6, A slice points to an array of values and also includes A length.

  []Tis a slice with elements of type T .

  

7. Slices can re-sliced, creating a new slice value that points to the same array.

[A, b] takes a value interval of a->b-1.

  

8, Making slices

  

  

9. The zero value of a slice is nil .

A nil slice has a length and capacity of 0.

  

For the above formula, Z is nil.

10. Add elements through the Append method.

  

11. Range can be used to iterate slices in for.

  

12, through _ can omit the index.

  

13. Maps must is created with make (not new ) before use

  

14, Map literals is like a struct literals, but the keys is required.

  

15, can omit vertex. If the top-level type is just a type name, you can omit it from the elements of the literal.

  

16. Operation of Map

  

17, the function is also a variable.

  

18, closure.

  

Reference: HTTPS://TOUR.GOLANG.ORG/MORETYPES/1

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.