简体   繁体   中英

Multi-dimensional array access with negative index

Ok, maybe I'm dumb, but Why there is no exception being thrown in the following code?

码

It's clear that the index by which the _cells array is being accessed is negative (posCol + col = -1) as shown in the picture.

Thanks in advance.

Most likely shape[row,col] is equal to 0. If it is, C# will short circuit the rest of the conditional since it can already determine the entire thing will evaluate to false. Since it never evaluates the second one with the negative index, it doesn't matter that posCol is negative.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM