LinkedList.Clear メソッドとは? わかりやすく解説

LinkedList.Clear メソッド

メモ : このメソッドは、.NET Framework version 2.0新しく追加されたものです。

LinkedList からすべてのノード削除します

名前空間: System.Collections.Generic
アセンブリ: System (system.dll 内)
構文構文

解説解説

Count は 0 に設定されコレクション要素からの他のオブジェクトへの参照解放されます。First および Last は、null 参照 (Visual Basic では Nothing) に設定されます。

このメソッドは O(n) 操作です。ここで、nCount です。

使用例使用例

Clear メソッドコード例および出力次に示します。このコード例では、リンク リストと同じサイズ配列作成しすべてのノードの値を配列要素 0 で始まる文字列配列コピーしてから、Clear メソッド使用して配列クリアます。

このコード例および出力は、LinkedList クラストピック取り上げている例の一部分です。

        ' Create an array, specifying a size one less than the size
        ' of the linked list, because Visual Basic allocates one 
        ' more element than you specify.
        Console.WriteLine(vbLf & "Copy the list to an array.")
        Dim sArray(sentence.Count - 1) As String
 
        sentence.CopyTo(sArray, 0)

        For Each s As String
 In sArray
            Console.WriteLine(s)
        Next

        ' Release all the nodes.
        sentence.Clear()
<br /><span space="preserve">...</span><br
 />'Copy the list to an array.
'the
'quick
'brown
'dog
'jumped
'over
'the
'lazy
'rhinoceros
        // Create an array with the same number of elements as the
        // linked list.
        Console.WriteLine("\nCopy the list to an array.");
        string[] sArray = new string[sentence.Count];
        sentence.CopyTo(sArray, 0);

        foreach( string s in
 sArray )
        {
            Console.WriteLine(s);
        }

        // Release all the nodes.
        sentence.Clear();
<br /><span space="preserve">...</span><br />//Copy
 the list to an array.
//the
//quick
//brown
//dog
//jumped
//over
//the
//lazy
//rhinoceros
    // Create an array with the same number of elements as the
    // linked list.
    Console::WriteLine("\nCopy the list to an array.");
    array<String^>^ sArray = gcnew array<String^>(sentence->Count);
    sentence->CopyTo(sArray, 0);

    for each( String^ s in sArray )
    {
        Console::WriteLine(s);
    }

    // Release all the nodes.
    sentence->Clear();
<br /><span space="preserve">...</span><br />//Copy
 the list to an array.
//the
//quick
//brown
//dog
//jumped
//over
//the
//lazy
//rhinoceros
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「LinkedList.Clear メソッド」の関連用語

LinkedList.Clear メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



LinkedList.Clear メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS