package main import ( "fmt" "reflect" ) func main() { arr := [5]int{1, 2, 3, 4, 5} fmt.Println("Length of array: ", reflect.TypeOf(arr).Len()) }
package main import ( "fmt" "reflect" ) func main() { type Person struct { Name string Age int } p := Person{"John", 30} fmt.Println("Length of struct: ", reflect.TypeOf(p).NumField()) }In this example, we create a `Person` struct with two fields, and use the `NumField` function to get the number of fields in the struct, which is 2. Package: `reflect`