Never seen something like this before. Specifically line 4. Currently I understand:
days array at position i-1 gets the value...
I don't know anything beyond the = sign excluding the concatenation from the +.
public String[] months() {
String[] days = new String[12];
for (int i = 1; i <= 12; i++) {
days[i - 1] = i < 10 ? "0" + Convert.ToString(i) : Convert.ToString(i);
}
return days;
}
Also why are there 2 converts?
Looking further into the other code I think the developer copied and pasted previous code. Days array should be months probably, as there are 12 months.
Solved
Thanks, never seen ternary operators before. Thanks!
public String[] months() {
String[] months = new String[12];
for (int i = 1; i <= 12; i++) {
/* faster way of saying */
/* if i < 10 {} else {} */
/* if condition is met do everything before the :, else do everything after */
/* checks for 10 because months can be 1 or 2 digits, 0-9, then 10-12 */
/* single digits concatenated to the 0 */
/* double digits replace the 0 */
months[i - 1] = i < 10 ? "0" + Convert.ToString(i) : Convert.ToString(i);
}
return months;
}