Golang Azərbaycan
  • Info
  • Go Compiler Installations
  • First Go Application
  • Build on Different Platforms
  • Values
  • Variables
  • Assignment Operators
  • Code Grouping Process
  • Type Conversion
  • Comments
  • Arithmetic Operators
  • Logical Operators
  • Relational Operators
  • Constants
  • if/else
  • For
  • Switch
  • Arrays
  • Slices
  • Maps
  • Range
  • Functions
    • Functions
    • Variadic function
    • Closures
    • Anonymous
    • Recursion
  • Empty Identifiers
  • Pointers
  • Strings and Runes
  • Structs
  • Anonymous struct
  • Method
  • Interface
  • Dynamic Variables
  • Generics
  • Struct embedding
  • Errors
  • Goroutines
  • Channel
  • Select
  • Timeouts
  • Non-Blocking Channel Operations
  • Closing Channels
  • Range over Channels
  • Timers
  • Ticker
  • Worker pools
  • WaitGroups
  • Rate Limiting
  • Atomic Counter
  • Sorting
  • Panic
  • Defer
  • String Functions
  • Recover
  • Text Templates
  • Json
  • Database
    • Mysql
    • Postgres
    • Mssql
Powered by GitBook
On this page
  • Anonim Struct Nümunəsi:
  • Output:
Edit on GitHub

Anonymous struct

Go dilində struct əlaqəli məlumatları qruplaşdırmaq üçün istifadə olunur. Adətən, struct-lar müəyyən bir adla elan olunur və bu, kod daxilində onlara müraciət etməyə və təkrar istifadə etməyə imkan verir. Lakin Go həmçinin anonim struct-ları da dəstəkləyir, yəni müəyyən olunmuş adı olmayan struct-lar.

Anonim struct-lar, yalnız müəyyən bir kontekstdə istifadə edilən, sadə və müvəqqəti strukturlar üçün faydalıdır. Onlar əsasən qısamüddətli məlumat strukturları üçün istifadə olunur.

Anonim Struct Nümunəsi:

package main

import "fmt"

func main() {
    person := struct {
        Name string
        Age  int
    }{
        Name: "Alice",
        Age:  30,
    }
	
    fmt.Println("Name:", person.Name)
    fmt.Println("Age:", person.Age)
}

Output:

Name: Alice
Age: 30

Bu nümunədə, anonim struct "Name" və "Age" məlumatlarını saxlamaq üçün yaradılır və person dəyişəninə təyin edilir. Struct-ın adı yoxdur və yalnız bu kod blokunda istifadə olunur.

PreviousStructsNextMethod

Last updated 8 months ago