getfield()
是 julia 中的一个内置函数,用于从复合类型的指定值中提取命名字段。
Syntax:
getfield(value, name::Symbol)
Parameters:
- value: Specified value of composite type.
- name::Symbol: Specified symbol.
Returns: It returns the extracted named field from the specified value of composite type.
示例 1:
# Julia program to illustrate
# the use of getfield() method
# Getting the extracted named field
# from the specified value of composite type.
a = 5//2
println(getfield(a, :num))
输出:
5
示例 2:
# Julia program to illustrate
# the use of getfield() method
# Getting the extracted named field
# from the specified value of composite type.
a = 7//3
println(getfield(a, :num))
输出:
7