It is a sum of derivatives, and the sign " + " is added every time it is solved. But in the last element you do not have to add the sign " + ". Please, help with that.
if(i<partes.Lenght-1){
funciones += x +'+'
} else {
funciones += x
}
When you are in the situation that you want all the elements to be processed in a certain way except the last one, sometimes it is useful to reverse the situation, that is to say that all the elements are processed the same except the first one.
An example, let's say you have an array var array = new [] { 1, 2, 3, 4 };
and you want it to be shown as a single string separated by commas like "1,2,3,4"
(only as a demonstration because the same could be achieved with string.Join(",", array)
)
On a first try maybe one would do something like this:
string result = "";
for (int i = 0; i < array.Length; i++)
{
result += array[i] + ",";
}
// ""
// 1,
// 1, 2,
// 1, 2, 3,
// 1, 2, 3, 4,
but this would return "1,2,3,4,"
with an extra comma at the end and the first solution that comes to mind is that the last element is the exception but I present an alternative:
string result = array[0].ToString();
for (int i = 1; i < array.Length; i++)
{
result += "," + array[i];
}
// 1
// 1 ,2
// 1 ,2 ,3
// 1 ,2 ,3 ,4
and this would return the expected result "1,2,3,4"
because now the first element is the one that we treat differently. With this you avoid having to include a if
within for
which makes the code cleaner.