Collection of Various Types

Hello There,

how can I create a collection type variable with different datatypes, for example, a collection of strings, numbers, arrays, lists, booleans, etc

Appreciate your Support
Hara

2 Likes

You can create a List type to store all types of data.
At the runtime you can convert to the required type.

Regards,
Karthik Byggari

3 Likes

Hi @Hara_Gopal
To create those type of datatypes in the studio
—in he variable panel select variable type and click on browse for types
There search as
System.Collections.Generic.
Under which we got
—List(of anydatatype)
—Dictionary(of anydatatype)

Goes on
While Array is different from collections
To create array type of variables
—same in variable panel click the drop down from variable type and click on Array() where we can choose Array(string), Array(int32),…
The are many differences while the simple one to differ them is Array is initialised and is of fixed size while collections can take any number values even after initialisation i.e., they can expand

So whatever type we choose among either array or collections (list,dictionary) we need to initialise in the variable panel like
For array
New integer(){n}
Where n is the size of the array
For list
New List(of string)
New List (of Int32)
For dictionary
New Dictionary (of string)(String)

Simple isn’t it
Cheers

1 Like

I think you want it to be a collection of type Object. Similar to how you would use a dictionary<Of String, Object> or a DataTable uses Object type for each item.

Then, you will need to convert it to the correct type at runtime like what was mentioned.
item.ToString or CStr(item)
Convert.ToInt32(item) or CInt(item)
CType(item, String())
et cetera

But to go along with that is you will need to validate that the type is the correct type before conversion.
If(IsNumeric(item), Convert.ToInt32(item), 0)

But, if anyone disagrees with this suggestion, please leave feedback. At the moment, it’s working well for me.

I even use an Object type for the TransactionData, so I can make it perform effectively no matter what type data is being processed in the Framework. (ie Array of Strings, Data Table, Array of Rows, etc)

EDIT: Also, this is assuming you want a collection or array of many different types in the same array. Otherwise, use the specific type if the items are all the same type

Regards.

2 Likes

Hi Palaniyappan,

Which mean we can only have one variable type for one New List, we cannot put integer and string together into a List?
Can i have the output written as
1,2,3,X,Y,z?

Thanks