- Home /
Strings arrays in strings array?
Hello,
I would like to know whether it is possible to build an array of strings in which each string contains a strings array.
For example:
I have an array of strings containing phone numbers and I would like to attach to each phone numbers an array of strings containing the different part of the speech of the called character.
For the moment I have the following variables
var phoneNumNumber : int; var phoneNumber : String[] = new String[phoneNumNumber]; var phoneTxt : String[] = new String[phoneNumNumber];
but with this system I can only attach one string for the text of the called character and I would like to be able to attach more.
Does anybody have an idea? If it is a stupid question, feel free to tell me. I am a beginner and I need to learn.
Thank you.
Answer by Kiwasi · Feb 19, 2015 at 09:09 AM
There are two ways to approach this.
The best would be to use a generic dictionary. See the reference here. A dictionary lets you use one object as a key and the other as a value. In your case you would use the name as the key and the phone number as the value.
The other way would be to build a struct that encapsulates both the name and the other data associated with the name.
In practice its common to use both solutions together.
Thank you for your answer. I am using JS and the link you gave me tells that it does not support generic types or methods. But I will investigate the second way and return if I still have problems.
Thank you.
Your answer
![](https://koobas.hobune.stream/wayback/20220613183729im_/https://answers.unity.com/themes/thub/images/avi.jpg)