0
In the example below, how I would fail to print the positions of this vector that are equal to 0
int[] caluculo = {50,6,0,59,6,7,0,6,8};
for(int i = 0 ; i < 9 ; i++)
{
Console.WriteLine("{0}",calculo[i]);
}
0
In the example below, how I would fail to print the positions of this vector that are equal to 0
int[] caluculo = {50,6,0,59,6,7,0,6,8};
for(int i = 0 ; i < 9 ; i++)
{
Console.WriteLine("{0}",calculo[i]);
}
5
Whenever you need to filter something you should if
:
for (var i = 0 ; i < 9 ; i++) if (calculo[i] != 0) WriteLine(calculo[i]);
Or you can do
foreach (var item in calculo) if (item != 0) WriteLine(item);
I put in the Github for future reference.
You can also use LINQ, but I don’t think it pays and it’s more advanced.
Browser other questions tagged c# .net array
You are not signed in. Login or sign up in order to post.
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