Exchanges the items at index and in the specified IList. - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:IList

Description

Exchanges the items at index and in the specified IList.

Demo Code

/*/*from   w w w  .j av a 2s .  com*/
    Copyright (C) 2007-2017 Team MediaPortal
    http://www.team-mediaportal.com

    This file is part of MediaPortal 2

    MediaPortal 2 is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    MediaPortal 2 is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with MediaPortal 2. If not, see <http://www.gnu.org/licenses/>.
*/
using System.Linq;
using System.Collections.Generic;
using System.Collections;
using System;

public class Main{
        /// <summary>
    /// Exchanges the items at index <paramref name="index1"/> and <paramref name="index2"/> in the specified
    /// <paramref name="list"/>.
    /// </summary>
    /// <typeparam name="T">Type of items in the list.</typeparam>
    /// <param name="list">List whose items should be swapped.</param>
    /// <param name="index1">First index to exchange.</param>
    /// <param name="index2">Second index to exchange.</param>
    public static void Swap<T>(IList<T> list, int index1, int index2)
    {
      T tmp = list[index1];
      list[index1] = list[index2];
      list[index2] = tmp;
    }
}

Related Tutorials