[問題] Array Offset?

作者: don750421 (1+1≠2)   2015-04-29 22:44:35
請問一下,Array有屬性可以將Array內的元素位移嗎?
假設有個string[] Temp = new string[]{"A","B","C","D",
"E","F","G","H"};
內有8個元素,每次固定往後位移兩個元素,所以會有四種Case..
[0]="A" [1]="B" [2]="C" [3]="D" [4]="E" [5]="F" [6]="G" [7]="H"
[0]="G" [1]="H" [2]="A" [3]="B" [4]="C" [5]="D" [6]="E" [7]="F"
[0]="E" [1]="F" [2]="G" [3]="H" [4]="A" [5]="B" [6]="C" [7]="D"
[0]="C" [1]="D" [2]="E" [3]="F" [4]="G" [5]="H" [6]="A" [7]="B"
還是只能透過迴圈塞一個新的Array??
謝謝
作者: Litfal (Litfal)   2015-04-30 04:28:00
string[] arr; int offset=2; int count=arr.Length;Array.Reverse(arr,0,offset);Array.Reverse(arr, offset, count-offset);Array.Reverse(arr);
作者: GoalBased (Artificail Intelligence)   2015-04-30 09:06:00
沒想到真有這功能..
作者: Litfal (Litfal)   2015-04-30 14:24:00
沒有的功能就自己作(無誤)
作者: YahooTaiwan (超可愛南西我老婆)   2015-05-01 01:58:00
為什麼不用一樓的解法?

Links booklink

Contact Us: admin [ a t ] ucptt.com