Declaring a computed array property causes syntax error

I have a project with a private property named m_CountryList() of type Country. The class Country is defined in my project. This compiles fine.

The associated protected computed property CountryList() of type Country, however, will not compile (won’t compile if public either). The error is “syntax error”.

If I remove both properties and replace them with protected property CountryList() (not computed), it compiles fine.

In retrospect this will work fine for me, but, unless I’m missing something, computed properties should be able to be arrays, no?

What I want is an array of Country instances that can be accessed. I was thinking in terms of lazy-populating it the first time it was accessed, and making it read-only, hence the computed property. I can live with a straight-up property but this seems like a bug to me. Is it?

Environment: 2022R2, Mac M1, 32G RAM. This is a debug compile.

No, computed properties can’t be arrays. You can simulate the syntax with a pair of normal methods, though:

Sub CountryList(Assigns NewArray() As Country) // setter

Function CountryList() As Country()  // getter
3 Likes

Thanks, Andrew. Seems like an odd limitation with a hack-y workaround, but thanks for this, I will probably use it.