Let's Go (11)

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

Objective:

Today will continue, the pit of their own digging must be filled, although the weather is very hot, but the slightest can not stop my pits enthusiasm, then, we continue to let us go!!!

Define the method:

Here we are going to look at the (Methods) method in Golang. We've talked about the Go language function (functions) in Go (ix), which is not a concept for today's approach. Familiarity with object-oriented students should know that, in general, we call the member function of the class methods (method). Go is an object-oriented language and of course there is this concept (although we haven't talked about Go's object-oriented programming yet). Said so much, for the code farm, code is the fastest way to show Ah, then immediately show you the code:

Oh yeah, in the above program, line 4th we define a new type of mystring, which is actually a string alias. Of course, you can define the type you want, such as the structure in the previous article.

The definition of this method seems to be different from the traditional object-oriented language, such as Java, and Java once you define a class, the corresponding Member method is also within the block of the class. The go language is more like a function bound to a type, see 12 lines (P person) getName () in the GetName before the method name is used () to pass a type to this method. This way the method becomes a method of the person. In this case, you have introduced yourself to the method, there is no need to have a Java this or Python self.

Summary:

Today this is, originally also want to write more, but still do not bother to write a lot of that kind of article, a day a little bit, make up ~

author: Sirk   
source: http:// Www.cnblogs.com/vimsk
this edition The right to the author and the blog Park is shared, welcome reprint, but without the consent of the author must retain this paragraph, and in the article page obvious location to the original link, otherwise reserves the right to pursue legal responsibility.

Related Article

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.