wwr
wwr

Reputation: 327

Is it possible to create a mixed array in vala?

In Vala I see that when I declare an array I have to specify the type, like

int[] myarray = { 1, 2, 3 };

I wonder if there is a way to have a mixed array like

smtg[] myarray = { 1, 'two', 3 };

I see that in this question they say that in C++ and C# it's not possible but I just started learning vala and I have no background with any C-like language so I want to be sure.

Upvotes: 3

Views: 159

Answers (1)

nemequ
nemequ

Reputation: 17522

No.

That said, you can create an array of something that can hold other types, like GLib.Value or GLib.Variant, and Vala can automatically convert to/from those two, so you could do something like

GLib.Value[] values = {
  1,
  "two",
  3.0
}

It's usually a terrible idea (you're basically throwing away compile time type safety), but you can do it.

Upvotes: 6

Related Questions