I'm new to programming (for 5 days). I wrote this code but index is always -1 (when 2 is expected) and I couldn't fix it.
My teacher wrote me just that:
Casting, Array.IndexOf(geburtsjahr, (int)1966);
I tried but still same.
This is my relevant code:
var geburtsjahr = new short[4] { 1998, 1992, 1966, 2006 };
// Expected: 2, Actual: -1
int index = Array.IndexOf(geburtsjahr, (int)1966);
Console.WriteLine(index);
I tried to see right index number (should be 2).
It works if you do either of these:
(1)
(2)
The issue is that there is no
intof any value in an array ofshortvalues, no matter what the numbers represent to us humans.