DEV Community

Assis Zang
Assis Zang

Posted on

Public C# methods VS public Go functions 🤺

In C# to create a public method you must use this:

public void CreateBook(Book book){
   //do something
}
Enter fullscreen mode Exit fullscreen mode

In Go to create a public function you must use this:

func CreateBook(product *structs.Product) error {
   //do something
}
Enter fullscreen mode Exit fullscreen mode

Note that in C# it is necessary to use the reserved word public and to create a private method, private is used.

In C# they are called Access Modifiers, there are others, you can check the complete list here: C# Access Modifiers - Reference.

In Go to differentiate public from private functions, the initial of the function name is used.

For public functions, capital letter is used. Example: CreateBook().

For private functions use lowercase initials. Example: createBook().

Top comments (0)