Moving elements in array c#

后端 未结 4 1491
感情败类
感情败类 2021-01-12 07:59

I have this very simple array which I want to be able to move around some items in. Are there any built in tools in c# to do this? If not, du you have any suggestion in how

4条回答
  •  被撕碎了的回忆
    2021-01-12 08:35

    It's an existing question:

    C# Array Move Item (Not ArrayList/Generic List)

    The answer is:

    void MoveWithinArray(Array array, int source, int dest)
    {
      Object temp = array.GetValue(source);
      Array.Copy(array, dest, array, dest + 1, source - dest);
      array.SetValue(temp, dest);
    }
    

提交回复
热议问题