# Struct instance that behaves as an array as well

**URL:** <https://discourse.julialang.org/t/struct-instance-that-behaves-as-an-array-as-well/62927>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [June 15, 2021, 6:19am UTC](https://discourse.julialang.org/t/struct-instance-that-behaves-as-an-array-as-well/62927 "2021-06-15T06:19:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kapple](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kapple/32/218915_2.png) [@kapple](https://discourse.julialang.org/u/kapple)\
**Post date:** [June 15, 2021, 6:19am UTC](https://discourse.julialang.org/t/struct-instance-that-behaves-as-an-array-as-well/62927/1 "2021-06-15T06:19:12Z")

</div>

For `sol::ODESolution` from DifferentialEquations.jl, it can be called as

```julia
sol[1:2, 2:3]

```

in addition to having properties to call and utilize.

How does one design a struct whose instances behave as such?

---

<div class="post-metadata">

**Author:** ![sostock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sostock/32/5546_2.png) [@sostock](https://discourse.julialang.org/u/sostock)\
**Post date:** [June 15, 2021, 6:42am UTC](https://discourse.julialang.org/t/struct-instance-that-behaves-as-an-array-as-well/62927/2 "2021-06-15T06:42:34Z")

</div>

To support indexing, a struct needs to implement an appropriate `getindex` method: `sol[1:2, 2:3]` is equivalent to `getindex(sol, 1:2, 2:3)`. An example is given [here](https://docs.julialang.org/en/v1/manual/interfaces/#Indexing) in the documentation.

The `ODESolution` type implements more than just `Base.getindex`. Since it is an actual `AbstractArray` subtype, it also has a `size` etc. The methods required for an `AbstractArray` are also listed on the documentation page linked above.
