Store all types of variables in an array/array?

Asked

Viewed 194 times

2

How can I store values and variables of all types within a vector? Ex:

vetor1.Add("valor em string");
vetor1.Add(100);
vetor1.Add(100.10);
vetor1.Add(-100);

I have no idea how I can do this.

  • 1

    Are you sure this is what you want? Recovering this data after can be laborious

  • Yes, according to the answer below Maniero, I found that to recover the data from object just give one cast.

1 answer

5


That doesn’t sound like a array rather a list. The general type for all types is the object, then just use it.

var vetor = new List<object>() { "string", 100, 100.10, -100 };

I put in the Github for future reference.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.