Skip to content

Commit 4aeaea7

Browse files
committed
readme.md增加了“数组位移”的说明
1 parent 963a67a commit 4aeaea7

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,3 +226,14 @@ char[] arrAlpha = { 'a', 'b', 'c', 'd', 'e', 'f', 'g' };
226226
char[] arr = ShuffleHelper.RandomGet(arrAlpha, 3);
227227
// arr为arrAlpha中的随机的3个元素,如:'d', 'f', 'b'
228228
```
229+
230+
## 数组位移
231+
232+
数组的位移就是直接根据需求挪动数组的元素。如数组```[1,2,3,4,5]``````[2,3]```子数组向右挪1个位置,数组就变成了```[1,4,2,3,5]```
233+
234+
注: 如果越界,会抛出```IndexOutOfRangeException```异常。
235+
```
236+
int[] arr = new int[]{1,2,3,4,5,6,7,8,9};
237+
ArrayHelper.ShiftArrayItems(arr, 7, 3, -5); //-5表示左移5位
238+
// arr为 [0, 1, 7, 8, 9, 2, 3, 4, 5, 6]
239+
```

0 commit comments

Comments
 (0)