「C#」Clear ()ですべての要素を削除するサンプル

構文
List<T>.Clear メソッド
List<T> からすべての要素を削除します。
public void Clear ();
C#コード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
using System;
using System.Linq;
using System.Collections.Generic;
namespace com.arkgame.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("Clear Before--Listの要素数:" + cftLst.Count);
cftLst.Clear();
Console.WriteLine("Clear after--Listの要素数:" + cftLst.Count);
}
}
}
using System; using System.Linq; using System.Collections.Generic; namespace com.arkgame.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("Clear Before--Listの要素数:" + cftLst.Count); cftLst.Clear(); Console.WriteLine("Clear after--Listの要素数:" + cftLst.Count); } } }
using System;
using System.Linq;
using System.Collections.Generic;

namespace com.arkgame.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("Clear Before--Listの要素数:" + cftLst.Count);
            cftLst.Clear();
            Console.WriteLine("Clear after--Listの要素数:" + cftLst.Count);


        }
    }
}

実行結果
Clear Before–Listの要素数:6
Clear after–Listの要素数:0

C#

Posted by arkgame