Here's my code:
String[] queries = new String[2];
int i = 0;
Boolean result;
queries[i++] = "<query 1>";
queries[i++] = "<query 2>"; //Warning shown here
result = dbOpenHelper.ExecuteMyTransaction(queries);
The second i++
gets highlighted and the warning 'The value changed at 'i++' is never used' is shown. This code was written by another person, and to my knowledge, here <query 1>
and <query 2>
get assigned to queries[1]
and queries[2]
respectively, but then it must show an error, as the array is of size 2. There's no error and this kind of confuses me on what's happening here. Can I safely remove the second assignment, or change the first one to queries[i]
?
The code is correct and you can safely ignore this warning or replace underlined i++
with just i
.
This warning simply indicates that as there's no further use of i
variable in that scope, so incrementing its value or not makes no effect and is simply pointless.
i++ means post increment, which means first the i value is taken and used, then is incremented.
your code is correct you can ignore this warning and try below code to get out of this warning
String[] queries = new String[2];
int i = 0;
Boolean result;
queries[i++] = "<query 1>";
queries[i] = "<query 2>"; //change this here
result = dbOpenHelper.ExecuteMyTransaction(queries);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With