var list = new List<int> { 1, 2, 3, 4 };
int getValue(int index) {
try {
return list[index];
}
catch (ArgumentOutOfRangeException ex) {
return -1;
}
}
int getValue(int index) {
if (index < list.Count) {
return list[index];
}
else {
return -1;
}
}