How does Array.GetLength (dimension) work in C #?

When used Array.GetLength(dimension)in C #, is the size of the array actually calculated every time it is called, or is it a cached / saved size and just what access does it matter?

What I really want to know is that if a local variable in the length of the array dimension adds any efficiency, if it is used in a large loop, or if I can just call array.GetLength () again and again w / o any speed limit.

+3
source share
4 answers

It is definitely a bad idea to start caching / optimizing yourself.

, (JIT). , , , .

, .

(int[][]) , (int[,]). int[,] . Fx2, , Fx4.

, hoisting ' Length.

+7

, , . , , , , 30% .

, , GetLength . , .

. Length , .

+1

, , . . , ?

. , - , !

0

- . "" (, Array.Length) .net , "Count" (, List.Count) / . ( .nets , Any, , , Count). GetLength Length , , .

- GetLength - - foreach, .

( ( ), , / . , , )

-1

Source: https://habr.com/ru/post/1753080/


All Articles