Hi there,
How can I create a record of variables that contains for example an Integer and a string?
And how can I create an array of it?
Thank you.
Hi there,
How can I create a record of variables that contains for example an Integer and a string?
And how can I create an array of it?
Thank you.
Not entirely sure I understand what you mean, but if you want an object that has a string variable and an integer just create a class
public class StringIntegerClass
{
private int _Integer;
private string _String;
//add constructor with parameters.
public StringIntegerClass()
{
_Integer = -1;
_String = "";
}
public int Integer
{
get
{
return _Integer;
}
set
{
_Integer = value;
}
//And same for string
}
}
Then you can have an array of StringIntegerClass
StringIntegerClass[] array = new StringIntegerClass[size];
//or generic list
List<StringIntegerClass> list = new List<StringIntegerClass>();
This is C# and javascript might have an “easier” way to do it.
Aha! The perfect opportunity to pimp my new Unity Wiki article:
Which Kind Of Array Or Collection Should I Use?
hope this helps!
You probably want a ‘Hashtable’, or if you’re using C#, and not targeting the iPhone, you could use a ‘Generic Dictionary’.
These are both explained in the wiki article linked above. Essentially they allow you to store “key/value pairs”, using code like this:
myData[key] = value;
Great wiki post!
Thank’s
I’m using java and I have more than two variables.
In pascal it’s very simpler. you can do somthing like this:
record foo;
r : real;
st : string;
ar : array[1…10] of real;
.
.
.
Is there a simpler way to do that?