# Overload \`\[\]\` operator for custom type

**URL:** https://discourse.julialang.org/t/overload-operator-for-custom-type/77266
**Category:** New to Julia
**Created:** [March 2, 2022, 1:33am UTC](https://discourse.julialang.org/t/overload-operator-for-custom-type/77266 "2022-03-02T01:33:07Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![kerim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kerim/32/37844_2.png) [@kerim](https://discourse.julialang.org/u/kerim)
#### Post date: [March 2, 2022, 1:33am UTC](https://discourse.julialang.org/t/overload-operator-for-custom-type/77266/1 "2022-03-02T01:33:07Z")

</div>

Hi,

I’m wondering is it possible to overload `[]` operator for my struct:

```julia
struct MyStruct
    x::Array{Float32,1}
    y::Array{Float32,1}
end

```

For example I would like when calling `my_var[i]` (myvar has type MyStruct) to be equal to summation of member variables at corresponding indexes: `MyStruct::x[i] + MyStruct::y[i]`.  
Is that possible?

---

<div class="post-metadata">

### Author: ![guoyongzhi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/guoyongzhi/32/28306_2.png) [@guoyongzhi](https://discourse.julialang.org/u/guoyongzhi)
#### Post date: [March 2, 2022, 1:41am UTC](https://discourse.julialang.org/t/overload-operator-for-custom-type/77266/2 "2022-03-02T01:41:19Z")

</div>

See [`getindex` and `setindex!`](https://docs.julialang.org/en/v1/manual/interfaces/#Indexing).
