Попробуйте for
l oop вместо foreach
,
string[] array1 = { "5", "4", "2" };
string[] array2 = { "1", "2", "3" };
for (int i=0; i < array1.Length; i++)
{
int a = (Convert.ToInt32(array1[i]) - Convert.ToInt32(array2[i]));
string b = Convert.ToString(a);
string removeValue = b.Replace("-", String.Empty);
if (Convert.ToInt32(array1[i]) > Convert.ToInt32(array2[i]))
{
mp += Negative + ",";
mpValue = mp.Split(',');
np += a + ",";
nposition = np.Split(',');
}
else
{
mp += Positive + ",";
mpValue = mp.Split(',');
np += removeValue + ",";
nposition = np.Split(',');
}
}
Или (то же самое)
string[] array1 = { "5", "4", "2" };
string[] array2 = { "1", "2", "3" };
for (int i=0; i<array1.Length; i++)
{
int arr1Ele = Convert.ToInt32(array1[i]);
int arr2Ele = Convert.ToInt32(array2[i]);
int a = arr1Ele - arr2Ele;
string b = Convert.ToString(a);
string removeValue = b.Replace("-", String.Empty);
if (arr1Ele > arr2Ele)
{
mp += Negative + ",";
mpValue = mp.Split(',');
np += a + ",";
nposition = np.Split(',');
}
else
{
mp += Positive + ",";
mpValue = mp.Split(',');
np += removeValue + ",";
nposition = np.Split(',');
}
}
Я надеюсь, что вычисляемая часть вашего кода правильный.