This is a creation in Article, where the information may have evolved or changed.
Objective:
This series has not aborted, continue the dystocia, haha, only blame I did not concentrate, in the period and secretly to learn Python,ruby,scala,haskell these several languages, if you are unfortunate is this series of readers, then you have to wait for the back of the later, can not wait a few years to see Ah ^_^. Because the go language is not so urgent need to use, and personal interest is more extensive, to play too many things, nature temporarily unable to complete the go learning. To the reader, can only say very sorry. Needless to say, today make up an article.
The Go Language enumeration definition:
In the go language, the enumeration is defined by the keyword const, which is used to define constants, the sample is quite powerful, and the enumeration can be defined:
In the above example, a enumeration about the week is defined, and the output is 5 when printing Friday. Print Sunday output 0. In fact, in the go language, the enumeration seems to be a constant a special form, but in the code above the occurrence of the keyword iota, this is a very useful thing, can help you write a lot of things, on top he will be initialized to 0, and then each row will be increased by 1, so it can be considered as a self-increment. So we don't have to write this: Sunday=1 monday=2 ... A iota to help you solve all the trouble, but also in the follow-up to iota operation: For example, can Monday = iota*2 so Monday is equal to 2. It says a line that defines a iota will increment the assignment to a constant, can you define more than one row? The answer is yes, but you have to specify the value explicitly, or you will get an error:
It is found that the values enumerated above are integers, and of course other types can, as long as the corresponding assignment is OK, such as Sunday = "Sun".
Definition of the structure of the Go language:
structure, for Learning C language should be very familiar with, for C such language, there is no class concept, the structure is to a large extent as the main way of encapsulation, then in the go language. What is the structure of the body? Please look down:
Is it similar to C language, if you look closely you will find that the first letter N of the struct is capitalized, and the first letter of age is lowercase. This is not a casual oh. Although I am casual here. In the go language, if the structure's field first letter is capitalized, it is public and can be accessed outside the package. When the first letter of age is lowercase, it can only be accessed in this package. Is the field of a class in Java similar to the private keyword or public definition?
In the code above we declare and initialize the ST variables together, and of course we can separate them:
There is another way to do this:
OK, today will be here, and then continue, let us gogogo together, enjoy the fun of programming ...
- author: Sirk
- source: http:// Www.cnblogs.com/vimsk
-
-
|