Maxim Levashov
Maxim Levashov

Reputation: 9

how to ignore IndexOutOfRangeException?

I need something like this:

string a = "12345"
if (a[5] == null) {
    //skip error and continue the cycle
}

So the question is, how to ignore that type of error?

Upvotes: 0

Views: 196

Answers (1)

Martin.Martinsson
Martin.Martinsson

Reputation: 2154

Make an additional length-check like:

if (a.Length >= 6 && a[5] == null) {}

but i think you mean something more like this:

if (a.Length >= 6 && a[5] == char.MinValue) {}

A char cannot be null. It can be '\0', which comes close to a "null".

Regards

Upvotes: 2

Related Questions