XOR Operation not working

Hello all,

I remember reading something a while back about the XOR operation not working, it does not look like this has been fixed? Can anyone confirm either way please?;


Xor operator evaluates both expressions. So, in the above condition, String.IsNullOrEmpty(Array2items(2).ToString) is always evaluated even if the number of items is 2 or less.

Perhaps you should use short-circuiting logical operator as the following.

Array2Items.Count<3 OrElse String.IsNullOrEmpty(Array2Items(2).ToString)



Your problem is you have an array with 2 items, which means the highest index is 1. You are referencing a third element, Array2Items(2).

In arrays, the first item is index 0, not index 1. So a 20 item array will have a highest index of 19, not 20. The 20 index would be the 21st item.

Are you trying to use the IsNullOrEmpty to see if there is a third item in the array? If so, that’s completely unnecessary. All you need is to look at the count of array items. Your If condition is redundant and will fail due to the reference to a third item. The third item is not null, it is not empty, it is nonexistent - hence “out of the bounds of the array.”

Hello Paul, thanks for your reply. Realised I was using the wrong operation OrElse was what I was after!

Thanks I realized I was using the wrong operation lol. OrElse was what I was after! Thanks

1 Like

But why? Checking the count of the array and then checking for a third element, is redundant and unnecessary. IsNullOrEmpty is not the appropriate way to figure out if an array element exists.

Oh no, sorry that was just for demonstration purposes. I had misunderstood how the XOR operator works. I thought it should not evaluate the second condition if the first condition is not true. I was looking for orElse

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.