0
I thought of the following code to calculate the square of each value in array:
double []vetor = {1,2,3,4,5,6,7,8,10};
double result = 0;
foreach(double posicao in vetor){
result = Math.Pow(posicao, 2);
vetor[result] = result;
}
Console.WriteLine($"{String.Join(" , ", vetor)}.");
This error appears:
error CS0266: Cannot implicitly Convert type
double' to
int'. An Explicit Conversion exists (are you Missing a cast?)
Your code problem is in: vector[result], the array indexer expects an integer, but you are accessing with a double.
– user178974
Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful to you. You can also vote on any question or answer you find useful on the entire site.
– Maniero