I have three different ints. Say for eg.
int one = 1;
int two = 2;
int three = 3;
I would like to assign these to a string that holds “123”. Easiest methods to understand appreciated!
Thanks.
I have three different ints. Say for eg.
int one = 1;
int two = 2;
int three = 3;
I would like to assign these to a string that holds “123”. Easiest methods to understand appreciated!
Thanks.
string x = one.ToString() + two.ToString() + three.ToString();
You can also use String.Format for this.
string x = string.Format("{0}{1}{2}", one, two, three);
The numbers in braces are placeholders. 0 corresponds to the first parameter after the format, 1 for the second parameter, and so on. Anything outside of braces will be added to the final string, so you can do things like:
string x = string.Format("{0}, {1}, {2}", one, two, three);
Which will output “1, 2, 3”. You can also add formatting and such which is explained in the link.