Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
20
Task/Named-parameters/Go/named-parameters.go
Normal file
20
Task/Named-parameters/Go/named-parameters.go
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type params struct {x, y, z int}
|
||||
|
||||
func myFunc(p params) int {
|
||||
return p.x + p.y + p.z
|
||||
}
|
||||
|
||||
func main() {
|
||||
r := myFunc(params{x: 1, y: 2, z: 3}) // all fields, same order
|
||||
fmt.Println("r =", r)
|
||||
s := myFunc(params{z: 3, y: 2, x: 1}) // all fields, different order
|
||||
fmt.Println("s =", s)
|
||||
t := myFunc(params{y: 2}) // only one field, others set to zero
|
||||
fmt.Println("t =", t)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue