I have a function that takes a string and returns a string. In it, I convert the string into an integer array and later try to multiply every other number like this:
private string addEveryOther(string x)
{
int[] d = x.Select(n => Convert.ToInt32(n)).ToArray();
for(int i = 0; i < 10; i++)
{
d[i] = d[i] * 2;
MessageBox.Show(d[i].ToString()); //Display the result?
i++;
}
// And later returning a string:
StringBuilder g = new StringBuilder();
foreach (int n in d)
{
g.Append(Convert.ToChar(n));
}
return g.ToString();
}
This works with addition, but not with multiplication as it returns strange values. If I input “3434343434” i expect it to return “6464646464”. Now it returns: “f4f4f4f4f4” and I don’t know why? Any suggestions how to go about it?
Based on the discussions above, I suppose your method should use ToString instead of Convert.ToChar.
EDIT: Using @Kirill’s Concat solution and @Reniuz comment in the addEveryOther method should hopefully solve the problem.