「C#」RemoveAtメソッドでインデックスを指定して要素を削除するサンプル

構文
public void RemoveAt (int index);
指定したインデックスにある IList 項目を削除します。
index
削除する項目の 0 から始まるインデックス。
C#コード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace com.arkgame.study.ConsoleAppDemo
{
class Program
{
static void Main(string[] args)
{
List<String> cftLst = new List<string>();
cftLst.Add("AA");
cftLst.Add("BB");
cftLst.Add("CC");
cftLst.Add("DD");
cftLst.Add("EE");
cftLst.Add("FF");
Console.WriteLine("インデックスを指定 要素削除前 before:");
foreach (var t in cftLst)
{
Console.WriteLine(t);
}
cftLst.RemoveAt(3);
cftLst.RemoveAt(4);
Console.WriteLine("インデックスを指定 要素削除後 after:");
foreach (var t in cftLst)
{
Console.WriteLine(t);
}
}
}
}
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace com.arkgame.study.ConsoleAppDemo { class Program { static void Main(string[] args) { List<String> cftLst = new List<string>(); cftLst.Add("AA"); cftLst.Add("BB"); cftLst.Add("CC"); cftLst.Add("DD"); cftLst.Add("EE"); cftLst.Add("FF"); Console.WriteLine("インデックスを指定 要素削除前 before:"); foreach (var t in cftLst) { Console.WriteLine(t); } cftLst.RemoveAt(3); cftLst.RemoveAt(4); Console.WriteLine("インデックスを指定 要素削除後 after:"); foreach (var t in cftLst) { Console.WriteLine(t); } } } }
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace com.arkgame.study.ConsoleAppDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            List<String> cftLst = new List<string>();
            cftLst.Add("AA");
            cftLst.Add("BB");
            cftLst.Add("CC");
            cftLst.Add("DD");
            cftLst.Add("EE");
            cftLst.Add("FF");
           Console.WriteLine("インデックスを指定 要素削除前 before:"); 
            foreach (var t in cftLst)
            {
                Console.WriteLine(t);
            }

            cftLst.RemoveAt(3);
            cftLst.RemoveAt(4);
            Console.WriteLine("インデックスを指定 要素削除後 after:");
            foreach (var t in cftLst)
            {
                Console.WriteLine(t);
            }
        }
    }
}

実行結果
インデックスを指定 要素削除前 before:
AA
BB
CC
DD
EE
FF
インデックスを指定 要素削除後 after:
AA
BB
CC
EE

C#

Posted by arkgame