Queueとは? わかりやすく解説

Queue クラス

オブジェクト先入れ先出しコレクション表します

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

<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public Class Queue
    Implements ICollection, IEnumerable, ICloneable
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public class Queue : ICollection, IEnumerable,
 ICloneable
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public ref class Queue : ICollection, IEnumerable,
 ICloneable
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public class Queue implements ICollection,
 IEnumerable, 
    ICloneable
SerializableAttribute 
ComVisibleAttribute(true) 
public class Queue implements ICollection,
 IEnumerable, 
    ICloneable
解説解説
使用例使用例

Queue作成して値を追加する方法と、その値を出力する方法の例を次に示します

Imports System
Imports System.Collections

Public Class SamplesQueue

    Public Shared Sub Main()

        ' Creates and initializes a new Queue.
        Dim myQ As New Queue()
        myQ.Enqueue("Hello")
        myQ.Enqueue("World")
        myQ.Enqueue("!")

        ' Displays the properties and values of the Queue.
        Console.WriteLine("myQ")
        Console.WriteLine("    Count:    {0}", myQ.Count)
        Console.Write("    Values:")
        PrintValues(myQ)

    End Sub 'Main

    Public Shared Sub PrintValues(myCollection
 As IEnumerable)
        Dim obj As [Object]
        For Each obj In
  myCollection
            Console.Write("    {0}", obj)
        Next obj
        Console.WriteLine()
    End Sub 'PrintValues

End Class 'SamplesQueue


' This code produces the following output.
' 
' myQ
'     Count:    3
'     Values:    Hello    World    !

 using System;
 using System.Collections;
 public class SamplesQueue  {
 
    public static void Main()
  {
 
       // Creates and initializes a new Queue.
       Queue myQ = new Queue();
       myQ.Enqueue("Hello");
       myQ.Enqueue("World");
       myQ.Enqueue("!");
 
       // Displays the properties and values of the Queue.
       Console.WriteLine( "myQ" );
       Console.WriteLine( "\tCount:    {0}", myQ.Count );
       Console.Write( "\tValues:" );
       PrintValues( myQ );
    }
 
 
    public static void PrintValues(
 IEnumerable myCollection )  {
       foreach ( Object obj in myCollection
 )
          Console.Write( "    {0}", obj );
       Console.WriteLine();
    }
 }
 /* 
 This code produces the following output.
 
 myQ
     Count:    3
     Values:    Hello    World    !
*/ 
using namespace System;
using namespace System::Collections;
void PrintValues( IEnumerable^ myCollection );
int main()
{
   
   // Creates and initializes a new Queue.
   Queue^ myQ = gcnew Queue;
   myQ->Enqueue( "Hello" );
   myQ->Enqueue( "World" );
   myQ->Enqueue( "!" );
   
   // Displays the properties and values of the Queue.
   Console::WriteLine( "myQ" );
   Console::WriteLine( "\tCount:    {0}", myQ->Count );
   Console::Write( "\tValues:" );
   PrintValues( myQ );
}

void PrintValues( IEnumerable^ myCollection )
{
   IEnumerator^ myEnum = myCollection->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      Object^ obj = safe_cast<Object^>(myEnum->Current);
      Console::Write( "    {0}", obj );
   }

   Console::WriteLine();
}

/* 
 This code produces the following output.
 
 myQ
     Count:    3
     Values:    Hello    World    !
*/
import System.*;
import System.Collections.*;

public class SamplesQueue
{
    public static void main(String[]
 args)
    {
        // Creates and initializes a new Queue.
        Queue myQ = new Queue();
        myQ.Enqueue("Hello");
        myQ.Enqueue("World");
        myQ.Enqueue("!");

        // Displays the properties and values of the Queue.
        Console.WriteLine("myQ");
        Console.WriteLine(
            "\tCount:    {0}",System.Convert.ToString(myQ.get_Count()));
        Console.Write("\tValues:");
        PrintValues(myQ);
    } //main

    public static void PrintValues(IEnumerable
 myCollection)
    {
        IEnumerator enumerator = myCollection.GetEnumerator();
        while(enumerator.MoveNext()) {
            Object obj = enumerator.get_Current();
            Console.Write("    {0}", obj);
        }
        Console.WriteLine();
    } //PrintValues
} //SamplesQueue

/* 
 This code produces the following output.
 
 myQ
     Count:    3
     Values:    Hello    World    !
 */
継承階層継承階層
System.Object
  System.Collections.Queue
スレッド セーフスレッド セーフ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
Queue メンバ
System.Collections 名前空間
System.Collections.Generic.Queue

Queue コンストラクタ ()

空で、既定初期量を備え既定増加率使用する、Queue クラス新しインスタンス初期化します。

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

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Queue コンストラクタ ()

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

空で、既定初期量を備えた、Queue クラス新しインスタンス初期化します。

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

解説解説
使用例使用例

このコンストラクタおよび Queue ジェネリック クラスのその他いくつかのメソッド使用したコード例次に示します。このコード例では、既定容量文字列キュー作成しEnqueue メソッド使用して 5 つ文字列キュー置きますキュー要素列挙されますが、キューの状態は変化しません。Dequeue メソッド使用して最初文字列キューから取り出しますPeek メソッド使用してキュー内の次の項目を調べてから、Dequeue メソッド使用してキューから取り出します

ToArray メソッド使用して配列作成し、その配列キュー要素コピーしてから、IEnumerable を受け取る Queue コンストラクタ配列渡してキューコピー作成しますコピー要素表示されます。

キューの 2 倍のサイズ配列作成されCopyTo メソッド使用して配列中央部で始まる配列要素コピーしますQueue コンストラクタ再度使用して先頭3 つの null 要素を含むキュー2 つ目のコピー作成します

Contains メソッドにより、文字列 "four" がキュー最初コピー含まれていることを示しますその後で、Clear メソッドコピークリアすると、Count プロパティによってキューが空であることが示されます。

Imports System
Imports System.Collections.Generic

Module Example

    Sub Main

        Dim numbers As New
 Queue(Of String)
        numbers.Enqueue("one")
        numbers.Enqueue("two")
        numbers.Enqueue("three")
        numbers.Enqueue("four")
        numbers.Enqueue("five")

        ' A queue can be enumerated without disturbing its contents.
        For Each number As
 String In numbers
            Console.WriteLine(number)
        Next

        Console.WriteLine(vbLf & "Dequeuing '{0}'", numbers.Dequeue())
        Console.WriteLine("Peek at next item to dequeue: {0}",
 _
            numbers.Peek())    
        Console.WriteLine("Dequeuing '{0}'", numbers.Dequeue())

        ' Create a copy of the queue, using the ToArray method and the
        ' constructor that accepts an IEnumerable(Of T).
        Dim queueCopy As New
 Queue(Of String)(numbers.ToArray())

        Console.WriteLine(vbLf & "Contents of the first copy:")
        For Each number As
 String In queueCopy
            Console.WriteLine(number)
        Next
        
        ' Create an array twice the size of the queue, compensating
        ' for the fact that Visual Basic allocates an extra array 
        ' element. Copy the elements of the queue, starting at the
        ' middle of the array. 
        Dim array2((numbers.Count * 2) - 1) As
 String
        numbers.CopyTo(array2, numbers.Count)
        
        ' Create a second queue, using the constructor that accepts
 an
        ' IEnumerable(Of T).
        Dim queueCopy2 As New
 Queue(Of String)(array2)

        Console.WriteLine(vbLf & _
            "Contents of the second copy, with duplicates and
 nulls:")
        For Each number As
 String In queueCopy2
            Console.WriteLine(number)
        Next

        Console.WriteLine(vbLf & "queueCopy.Contains(""four"")
 = {0}", _
            queueCopy.Contains("four"))

        Console.WriteLine(vbLf & "queueCopy.Clear()")
        queueCopy.Clear()
        Console.WriteLine(vbLf & "queueCopy.Count = {0}",
 _
            queueCopy.Count)
    End Sub
End Module

' This code example produces the following output:
'
'one
'two
'three
'four
'five
'
'Dequeuing 'one'
'Peek at next item to dequeue: two
'
'Dequeuing 'two'
'
'Contents of the copy:
'three
'four
'five
'
'Contents of the second copy, with duplicates and nulls:
'
'
'
'three
'four
'five
'
'queueCopy.Contains("four") = True
'
'queueCopy.Clear()
'
'queueCopy.Count = 0
using System;
using System.Collections.Generic;

class Example
{
    public static void Main()
    {
        Queue<string> numbers = new Queue<string>();
        numbers.Enqueue("one");
        numbers.Enqueue("two");
        numbers.Enqueue("three");
        numbers.Enqueue("four");
        numbers.Enqueue("five");

        // A queue can be enumerated without disturbing its contents.
        foreach( string number in
 numbers )
        {
            Console.WriteLine(number);
        }

        Console.WriteLine("\nDequeuing '{0}'", numbers.Dequeue());
        Console.WriteLine("Peek at next item to dequeue: {0}", 
            numbers.Peek());
        Console.WriteLine("Dequeuing '{0}'", numbers.Dequeue());

        // Create a copy of the queue, using the ToArray method and
 the
        // constructor that accepts an IEnumerable<T>.
        Queue<string> queueCopy = new
 Queue<string>(numbers.ToArray());

        Console.WriteLine("\nContents of the first copy:");
        foreach( string number in
 queueCopy )
        {
            Console.WriteLine(number);
        }
        
        // Create an array twice the size of the queue and copy the
        // elements of the queue, starting at the middle of the 
        // array. 
        string[] array2 = new string[numbers.Count
 * 2];
        numbers.CopyTo(array2, numbers.Count);
        
        // Create a second queue, using the constructor that accepts
 an
        // IEnumerable(Of T).
        Queue<string> queueCopy2 = new
 Queue<string>(array2);

        Console.WriteLine("\nContents of the second copy, with duplicates and
 nulls:");
        foreach( string number in
 queueCopy2 )
        {
            Console.WriteLine(number);
        }

        Console.WriteLine("\nqueueCopy.Contains(\"four\") = {0}",
 
            queueCopy.Contains("four"));

        Console.WriteLine("\nqueueCopy.Clear()");
        queueCopy.Clear();
        Console.WriteLine("\nqueueCopy.Count = {0}", queueCopy.Count);
    }
}

/* This code example produces the following output:

one
two
three
four
five

Dequeuing 'one'
Peek at next item to dequeue: two
Dequeuing 'two'

Contents of the copy:
three
four
five

Contents of the second copy, with duplicates and nulls:



three
four
five

queueCopy.Contains("four") = True

queueCopy.Clear()

queueCopy.Count = 0
 */
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Queue コンストラクタ (Int32, Single)

空で、指定した初期量を備え指定した増加率使用するQueue クラス新しインスタンス初期化します。

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

Public Sub New ( _
    capacity As Integer, _
    growFactor As Single _
)
Dim capacity As Integer
Dim growFactor As Single

Dim instance As New Queue(capacity,
 growFactor)
public Queue (
    int capacity,
    float growFactor
)
public:
Queue (
    int capacity, 
    float growFactor
)
public Queue (
    int capacity, 
    float growFactor
)
public function Queue (
    capacity : int, 
    growFactor : float
)

パラメータ

capacity

Queue が格納できる要素数の初期値

growFactor

Queue容量拡張するときに使用する係数

例外例外
例外種類条件

ArgumentOutOfRangeException

capacity が 0 未満です。

または

growFactor1.0 未満であるか、10.0超えてます。

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Queue コンストラクタ (Int32)

空で、指定した初期量を備え既定増加率使用するQueue クラス新しインスタンス初期化します。

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

例外例外
例外種類条件

ArgumentOutOfRangeException

capacity が 0 未満です。

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Queue コンストラクタ (Int32)

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

空で、指定した初期量を備えたQueue クラス新しインスタンス初期化します。

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

例外例外
例外種類条件

ArgumentOutOfRangeException

capacity が 0 未満です。

解説解説

Queue容量は、Queue保持できる要素数になりますQueue要素追加すると、必要に応じて内部配列の再割り当てによって容量自動的に増加します。

コレクションサイズ推定できる場合は、初期量を指定すると、Queue要素追加するときに、サイズ変更操作何度も実行する必要がなくなります

容量を減らすには、TrimExcess を呼び出します。

このコンストラクタは O(n) 操作です。ここで、ncapacity です。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Queue コンストラクタ (ジェネリック IEnumerable)

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

指定したコレクションからコピーした要素格納しコピーされる要素の数を格納できるだけの容量備えたQueue クラス新しインスタンス初期化します。

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

Public Sub New ( _
    collection As IEnumerable(Of T) _
)
Dim collection As IEnumerable(Of
 T)

Dim instance As New Queue(Of
 T)(collection)
public Queue (
    IEnumerable<T> collection
)
public:
Queue (
    IEnumerable<T>^ collection
)
public Queue (
    IEnumerable<T> collection
)
public function Queue (
    collection : IEnumerable<T>
)

パラメータ

collection

新しい Queue に要素コピーされコレクション

例外例外
例外種類条件

ArgumentNullException

collectionnull 参照 (Visual Basic では Nothing) です。

解説解説

Queue容量は、Queue保持できる要素数になりますQueue要素追加すると、必要に応じて内部配列の再割り当てによって容量自動的に増加します。

コレクションサイズ推定できる場合は、初期量を指定すると、Queue要素追加するときに、サイズ変更操作何度も実行する必要がなくなります

容量を減らすには、TrimExcess を呼び出します。

要素は、コレクションの IEnumerator によって読み取られる順序と同じ順序で、Queueコピーされます。

このコンストラクタは O(n) 操作です。ここで、ncollection 内の要素数です。

使用例使用例

このコンストラクタおよび Queue ジェネリック クラスのその他いくつかのメソッド使用したコード例次に示します。このコード例では、既定容量文字列キュー作成しEnqueue メソッド使用して 5 つ文字列キュー置きますキュー要素列挙されますが、キューの状態は変化しません。Dequeue メソッド使用して最初文字列キューから取り出しますPeek メソッド使用してキュー内の次の項目を調べてから、Dequeue メソッド使用してキューから取り出します

ToArray メソッド使用して配列作成し、その配列キュー要素コピーしてから、IEnumerable を受け取Queue コンストラクタ配列渡してキューコピー作成しますコピー要素表示されます。

キューの 2 倍のサイズ配列作成されCopyTo メソッド使用して配列中央部で始まる配列要素コピーしますQueue コンストラクタ再度使用して先頭3 つの null 要素を含むキュー2 つ目のコピー作成します

Contains メソッドにより、文字列 "four" がキュー最初コピー含まれていることを示しますその後で、Clear メソッドコピークリアすると、Count プロパティによってキューが空であることが示されます。

Imports System
Imports System.Collections.Generic

Module Example

    Sub Main

        Dim numbers As New
 Queue(Of String)
        numbers.Enqueue("one")
        numbers.Enqueue("two")
        numbers.Enqueue("three")
        numbers.Enqueue("four")
        numbers.Enqueue("five")

        ' A queue can be enumerated without disturbing its contents.
        For Each number As
 String In numbers
            Console.WriteLine(number)
        Next

        Console.WriteLine(vbLf & "Dequeuing '{0}'", numbers.Dequeue())
        Console.WriteLine("Peek at next item to dequeue: {0}",
 _
            numbers.Peek())    
        Console.WriteLine("Dequeuing '{0}'", numbers.Dequeue())

        ' Create a copy of the queue, using the ToArray method and the
        ' constructor that accepts an IEnumerable(Of T).
        Dim queueCopy As New
 Queue(Of String)(numbers.ToArray())

        Console.WriteLine(vbLf & "Contents of the first copy:")
        For Each number As
 String In queueCopy
            Console.WriteLine(number)
        Next
        
        ' Create an array twice the size of the queue, compensating
        ' for the fact that Visual Basic allocates an extra array 
        ' element. Copy the elements of the queue, starting at the
        ' middle of the array. 
        Dim array2((numbers.Count * 2) - 1) As
 String
        numbers.CopyTo(array2, numbers.Count)
        
        ' Create a second queue, using the constructor that accepts
 an
        ' IEnumerable(Of T).
        Dim queueCopy2 As New
 Queue(Of String)(array2)

        Console.WriteLine(vbLf & _
            "Contents of the second copy, with duplicates and
 nulls:")
        For Each number As
 String In queueCopy2
            Console.WriteLine(number)
        Next

        Console.WriteLine(vbLf & "queueCopy.Contains(""four"")
 = {0}", _
            queueCopy.Contains("four"))

        Console.WriteLine(vbLf & "queueCopy.Clear()")
        queueCopy.Clear()
        Console.WriteLine(vbLf & "queueCopy.Count = {0}",
 _
            queueCopy.Count)
    End Sub
End Module

' This code example produces the following output:
'
'one
'two
'three
'four
'five
'
'Dequeuing 'one'
'Peek at next item to dequeue: two
'
'Dequeuing 'two'
'
'Contents of the copy:
'three
'four
'five
'
'Contents of the second copy, with duplicates and nulls:
'
'
'
'three
'four
'five
'
'queueCopy.Contains("four") = True
'
'queueCopy.Clear()
'
'queueCopy.Count = 0
using System;
using System.Collections.Generic;

class Example
{
    public static void Main()
    {
        Queue<string> numbers = new Queue<string>();
        numbers.Enqueue("one");
        numbers.Enqueue("two");
        numbers.Enqueue("three");
        numbers.Enqueue("four");
        numbers.Enqueue("five");

        // A queue can be enumerated without disturbing its contents.
        foreach( string number in
 numbers )
        {
            Console.WriteLine(number);
        }

        Console.WriteLine("\nDequeuing '{0}'", numbers.Dequeue());
        Console.WriteLine("Peek at next item to dequeue: {0}", 
            numbers.Peek());
        Console.WriteLine("Dequeuing '{0}'", numbers.Dequeue());

        // Create a copy of the queue, using the ToArray method and
 the
        // constructor that accepts an IEnumerable<T>.
        Queue<string> queueCopy = new
 Queue<string>(numbers.ToArray());

        Console.WriteLine("\nContents of the first copy:");
        foreach( string number in
 queueCopy )
        {
            Console.WriteLine(number);
        }
        
        // Create an array twice the size of the queue and copy the
        // elements of the queue, starting at the middle of the 
        // array. 
        string[] array2 = new string[numbers.Count
 * 2];
        numbers.CopyTo(array2, numbers.Count);
        
        // Create a second queue, using the constructor that accepts
 an
        // IEnumerable(Of T).
        Queue<string> queueCopy2 = new
 Queue<string>(array2);

        Console.WriteLine("\nContents of the second copy, with duplicates and
 nulls:");
        foreach( string number in
 queueCopy2 )
        {
            Console.WriteLine(number);
        }

        Console.WriteLine("\nqueueCopy.Contains(\"four\") = {0}",
 
            queueCopy.Contains("four"));

        Console.WriteLine("\nqueueCopy.Clear()");
        queueCopy.Clear();
        Console.WriteLine("\nqueueCopy.Count = {0}", queueCopy.Count);
    }
}

/* This code example produces the following output:

one
two
three
four
five

Dequeuing 'one'
Peek at next item to dequeue: two
Dequeuing 'two'

Contents of the copy:
three
four
five

Contents of the second copy, with duplicates and nulls:



three
four
five

queueCopy.Contains("four") = True

queueCopy.Clear()

queueCopy.Count = 0
 */
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Queue コンストラクタ (ICollection)

指定したコレクションからコピーした要素格納しコピーした要素の数と同じ初期量を備え既定増加率使用する、Queue クラス新しインスタンス初期化します。

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

Public Sub New ( _
    col As ICollection _
)
Dim col As ICollection

Dim instance As New Queue(col)
public Queue (
    ICollection col
)
public:
Queue (
    ICollection^ col
)
public Queue (
    ICollection col
)
public function Queue (
    col : ICollection
)

パラメータ

col

要素コピー元の ICollection。

例外例外
例外種類条件

ArgumentNullException

colnull 参照 (Visual Basic では Nothing) です。

解説解説

Queue容量は、Queue保持できる要素数になりますQueue要素追加すると、必要に応じて、再割り当てを行うことによって容量自動的に増加します。容量を減らすには、TrimToSize を呼び出します。

増加率は、容量増やす必要がある場合に、現在の容量掛け合わせる数値です。増加率Queue生成され時点決定します

要素は、ICollection の IEnumerator によって読み取られる順序と同じ順序で、Queueコピーされます。

このコンストラクタは O(n) 操作です (ncol 内の要素数)。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Queue コンストラクタ


Queue コンストラクタ


Queue ジェネリック クラス

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

オブジェクト先入れ先出しコレクション表します

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

<SerializableAttribute> _
<ComVisibleAttribute(False)> _
Public Class Queue(Of T)
    Implements IEnumerable(Of T), ICollection,
 _
    IEnumerable
[SerializableAttribute] 
[ComVisibleAttribute(false)] 
public class Queue<T> : IEnumerable<T>,
 ICollection, 
    IEnumerable
[SerializableAttribute] 
[ComVisibleAttribute(false)] 
generic<typename T>
public ref class Queue : IEnumerable<T>,
 ICollection, 
    IEnumerable
J# では、ジェネリックな型およびメソッド使用できますが、新規に宣言することはできません。
JScript では、ジェネリックな型およびメソッド使用できません。

型パラメータ

T

キュー内の要素の型を指定します

解説解説
使用例使用例

Queue ジェネリック クラスいくつかのメソッド使用したコード例次に示します。このコード例では、既定容量文字列キュー作成しEnqueue メソッド使用して 5 つ文字列キュー置きますキュー要素列挙されますが、キューの状態は変化しません。Dequeue メソッド使用して最初文字列キューから取り出しますPeek メソッド使用してキュー内の次の項目を調べてから、Dequeue メソッド使用してキューから取り出します

ToArray メソッド使用して配列作成し、その配列キュー要素コピーしてから、IEnumerable を受け取る Queue コンストラクタ配列渡してキューコピー作成しますコピー要素表示されます。

キューの 2 倍のサイズ配列作成されCopyTo メソッド使用して配列中央部で始まる配列要素コピーしますQueue コンストラクタ再度使用して先頭3 つの null 要素を含むキュー2 つ目のコピー作成します

Contains メソッドにより、文字列 "four" がキュー最初コピー含まれていることを示しますその後で、Clear メソッドコピークリアすると、Count プロパティによってキューが空であることが示されます。

Imports System
Imports System.Collections.Generic

Module Example

    Sub Main

        Dim numbers As New
 Queue(Of String)
        numbers.Enqueue("one")
        numbers.Enqueue("two")
        numbers.Enqueue("three")
        numbers.Enqueue("four")
        numbers.Enqueue("five")

        ' A queue can be enumerated without disturbing its contents.
        For Each number As
 String In numbers
            Console.WriteLine(number)
        Next

        Console.WriteLine(vbLf & "Dequeuing '{0}'", numbers.Dequeue())
        Console.WriteLine("Peek at next item to dequeue: {0}",
 _
            numbers.Peek())    
        Console.WriteLine("Dequeuing '{0}'", numbers.Dequeue())

        ' Create a copy of the queue, using the ToArray method and the
        ' constructor that accepts an IEnumerable(Of T).
        Dim queueCopy As New
 Queue(Of String)(numbers.ToArray())

        Console.WriteLine(vbLf & "Contents of the first copy:")
        For Each number As
 String In queueCopy
            Console.WriteLine(number)
        Next
        
        ' Create an array twice the size of the queue, compensating
        ' for the fact that Visual Basic allocates an extra array 
        ' element. Copy the elements of the queue, starting at the
        ' middle of the array. 
        Dim array2((numbers.Count * 2) - 1) As
 String
        numbers.CopyTo(array2, numbers.Count)
        
        ' Create a second queue, using the constructor that accepts
 an
        ' IEnumerable(Of T).
        Dim queueCopy2 As New
 Queue(Of String)(array2)

        Console.WriteLine(vbLf & _
            "Contents of the second copy, with duplicates and
 nulls:")
        For Each number As
 String In queueCopy2
            Console.WriteLine(number)
        Next

        Console.WriteLine(vbLf & "queueCopy.Contains(""four"")
 = {0}", _
            queueCopy.Contains("four"))

        Console.WriteLine(vbLf & "queueCopy.Clear()")
        queueCopy.Clear()
        Console.WriteLine(vbLf & "queueCopy.Count = {0}",
 _
            queueCopy.Count)
    End Sub
End Module

' This code example produces the following output:
'
'one
'two
'three
'four
'five
'
'Dequeuing 'one'
'Peek at next item to dequeue: two
'
'Dequeuing 'two'
'
'Contents of the copy:
'three
'four
'five
'
'Contents of the second copy, with duplicates and nulls:
'
'
'
'three
'four
'five
'
'queueCopy.Contains("four") = True
'
'queueCopy.Clear()
'
'queueCopy.Count = 0
using System;
using System.Collections.Generic;

class Example
{
    public static void Main()
    {
        Queue<string> numbers = new Queue<string>();
        numbers.Enqueue("one");
        numbers.Enqueue("two");
        numbers.Enqueue("three");
        numbers.Enqueue("four");
        numbers.Enqueue("five");

        // A queue can be enumerated without disturbing its contents.
        foreach( string number in
 numbers )
        {
            Console.WriteLine(number);
        }

        Console.WriteLine("\nDequeuing '{0}'", numbers.Dequeue());
        Console.WriteLine("Peek at next item to dequeue: {0}", 
            numbers.Peek());
        Console.WriteLine("Dequeuing '{0}'", numbers.Dequeue());

        // Create a copy of the queue, using the ToArray method and
 the
        // constructor that accepts an IEnumerable<T>.
        Queue<string> queueCopy = new
 Queue<string>(numbers.ToArray());

        Console.WriteLine("\nContents of the first copy:");
        foreach( string number in
 queueCopy )
        {
            Console.WriteLine(number);
        }
        
        // Create an array twice the size of the queue and copy the
        // elements of the queue, starting at the middle of the 
        // array. 
        string[] array2 = new string[numbers.Count
 * 2];
        numbers.CopyTo(array2, numbers.Count);
        
        // Create a second queue, using the constructor that accepts
 an
        // IEnumerable(Of T).
        Queue<string> queueCopy2 = new
 Queue<string>(array2);

        Console.WriteLine("\nContents of the second copy, with duplicates and
 nulls:");
        foreach( string number in
 queueCopy2 )
        {
            Console.WriteLine(number);
        }

        Console.WriteLine("\nqueueCopy.Contains(\"four\") = {0}",
 
            queueCopy.Contains("four"));

        Console.WriteLine("\nqueueCopy.Clear()");
        queueCopy.Clear();
        Console.WriteLine("\nqueueCopy.Count = {0}", queueCopy.Count);
    }
}

/* This code example produces the following output:

one
two
three
four
five

Dequeuing 'one'
Peek at next item to dequeue: two
Dequeuing 'two'

Contents of the copy:
three
four
five

Contents of the second copy, with duplicates and nulls:



three
four
five

queueCopy.Contains("four") = True

queueCopy.Clear()

queueCopy.Count = 0
 */
継承階層継承階層
System.Object
  System.Collections.Generic.Queue
スレッド セーフスレッド セーフ

この型の public static (Visual Basic では Shared) メンバは、スレッド セーフです。すべてのインスタンス メンバスレッド セーフになるかどうか保証されていません。

コレクション変更されない限りQueue では、複数読み込み操作同時に発生して問題ありません。ただし、コレクション列挙処理は、本質的にスレッド セーフな処理ではありません。すべての列挙処理が終わるまでコレクションロックすることにより、列挙処理でのスレッド セーフ確保できますコレクション対し複数スレッドアクセスして読み取り書き込みを行うことができるようにするには、独自に同期化実装する必要があります

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
Queue メンバ
System.Collections.Generic 名前空間

Queue プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ SyncRoot Queue へのアクセス同期するために使用できるオブジェクト取得します
参照参照

関連項目

Queue クラス
System.Collections 名前空間
System.Collections.Generic.Queue

Queue プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ Count Queue に格納されている要素の数を取得します
明示的インターフェイスの実装明示的インターフェイス実装
  名前 説明
インターフェイスの明示的な実装 System.Collections.ICollection.SyncRoot ICollection へのアクセス同期するために使用できるオブジェクト取得します
参照参照

関連項目

Queue ジェネリック クラス
System.Collections.Generic 名前空間

Queue メソッド


パブリック メソッドパブリック メソッド

( プロテクト メソッド参照)
  名前 説明
パブリック メソッド Clear Queue からすべてのオブジェクト削除します
パブリック メソッド Contains ある要素Queue 内に存在するかどうか判断します
パブリック メソッド CopyTo Queue要素既存1 次元Arrayコピーしますコピー操作は、配列内の指定したインデックスから始まります
パブリック メソッド Dequeue Queue先頭にあるオブジェクト削除し返します
パブリック メソッド Enqueue Queue末尾オブジェクト追加します
パブリック メソッド Equals  オーバーロードされます2 つObject インスタンス等しかどうか判断します。 ( Object から継承されます。)
パブリック メソッド GetEnumerator Queue反復処理する列挙子を返します
パブリック メソッド GetHashCode  特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用適してます。 ( Object から継承されます。)
パブリック メソッド GetType  現在のインスタンスType取得します。 ( Object から継承されます。)
パブリック メソッド Peek Queue先頭にあるオブジェクト削除せず返します
パブリック メソッド ReferenceEquals  指定した複数Object インスタンス同一かどうか判断します。 ( Object から継承されます。)
パブリック メソッド ToArray Queue要素新し配列コピーします
パブリック メソッド ToString  現在の Object を表す String返します。 ( Object から継承されます。)
パブリック メソッド TrimExcess Queue 内にある実際要素数が現在の容量90% 未満場合は、容量をその数に設定します
プロテクト メソッドプロテクト メソッド
明示的インターフェイスの実装明示的インターフェイス実装
  名前 説明
インターフェイスの明示的な実装 System.Collections.Generic.IEnumerable<T>.GetEnumerator コレクション反復処理する列挙子を返します
インターフェイスの明示的な実装 System.Collections.ICollection.CopyTo ICollection の要素ArrayコピーしますArray特定のインデックスからコピー開始されます。
インターフェイスの明示的な実装 System.Collections.IEnumerable.GetEnumerator コレクション反復処理する列挙子を返します
参照参照

関連項目

Queue ジェネリック クラス
System.Collections.Generic 名前空間

Queue メソッド


パブリック メソッドパブリック メソッド

( プロテクト メソッド参照)
  名前 説明
パブリック メソッド Clear Queue からすべてのオブジェクト削除します
パブリック メソッド Clone Queue簡易コピー作成します
パブリック メソッド Contains ある要素Queue 内に存在するかどうか判断します
パブリック メソッド CopyTo Queue要素既存1 次元Arrayコピーしますコピー操作は、配列内の指定したインデックスから始まります
パブリック メソッド Dequeue Queue先頭にあるオブジェクト削除し返します
パブリック メソッド Enqueue Queue末尾オブジェクト追加します
パブリック メソッド Equals  オーバーロードされます2 つObject インスタンス等しかどうか判断します。 ( Object から継承されます。)
パブリック メソッド GetEnumerator Queue反復処理する列挙子を返します
パブリック メソッド GetHashCode  特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用適してます。 ( Object から継承されます。)
パブリック メソッド GetType  現在のインスタンスType取得します。 ( Object から継承されます。)
パブリック メソッド Peek Queue先頭にあるオブジェクト削除せず返します
パブリック メソッド ReferenceEquals  指定した複数Object インスタンス同一かどうか判断します。 ( Object から継承されます。)
パブリック メソッド Synchronized 同期されている (スレッド セーフな) Queue ラッパー返します
パブリック メソッド ToArray Queue要素新し配列コピーします
パブリック メソッド ToString  現在の Object を表す String返します。 ( Object から継承されます。)
パブリック メソッド TrimToSize 容量Queue 内にある実際要素数に設定します
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

Queue クラス
System.Collections 名前空間
System.Collections.Generic.Queue

Queue メンバ

オブジェクト先入れ先出しコレクション表します

Queue ジェネリック型公開されるメンバを以下の表に示します


パブリック コンストラクタパブリック コンストラクタ
パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ Count Queue格納されている要素の数を取得します
パブリック メソッドパブリック メソッド
( プロテクト メソッド参照)
  名前 説明
パブリック メソッド Clear Queue からすべてのオブジェクト削除します
パブリック メソッド Contains ある要素Queue 内に存在するかどうか判断します
パブリック メソッド CopyTo Queue要素既存1 次元Arrayコピーしますコピー操作は、配列内の指定したインデックスから始まります
パブリック メソッド Dequeue Queue先頭にあるオブジェクト削除し返します
パブリック メソッド Enqueue Queue末尾オブジェクト追加します
パブリック メソッド Equals  オーバーロードされます2 つObject インスタンス等しかどうか判断します。 (Object から継承されます。)
パブリック メソッド GetEnumerator Queue反復処理する列挙子を返します
パブリック メソッド GetHashCode  特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用適してます。 (Object から継承されます。)
パブリック メソッド GetType  現在のインスタンスType取得します。 (Object から継承されます。)
パブリック メソッド Peek Queue先頭にあるオブジェクト削除せず返します
パブリック メソッド ReferenceEquals  指定した複数Object インスタンス同一かどうか判断します。 (Object から継承されます。)
パブリック メソッド ToArray Queue要素新し配列コピーします
パブリック メソッド ToString  現在の Object を表す String返します。 (Object から継承されます。)
パブリック メソッド TrimExcess Queue 内にある実際要素数が現在の容量90% 未満場合は、容量をその数に設定します
プロテクト メソッドプロテクト メソッド
明示的インターフェイスの実装明示的インターフェイス実装
  名前 説明
インターフェイスの明示的な実装 System.Collections.Generic.IEnumerable<T>.GetEnumerator コレクション反復処理する列挙子を返します
インターフェイスの明示的な実装 System.Collections.ICollection.CopyTo ICollection の要素ArrayコピーしますArray特定のインデックスからコピー開始されます。
インターフェイスの明示的な実装 System.Collections.IEnumerable.GetEnumerator コレクション反復処理する列挙子を返します
インターフェイスの明示的な実装 System.Collections.ICollection.SyncRoot ICollection へのアクセス同期するために使用できるオブジェクト取得します
参照参照

関連項目

Queue ジェネリック クラス
System.Collections.Generic 名前空間

Queue メンバ

オブジェクト先入れ先出しコレクション表します

Queue データ型公開されるメンバを以下の表に示します


パブリック コンストラクタパブリック コンストラクタ
パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ SyncRoot Queue へのアクセス同期するために使用できるオブジェクト取得します
パブリック メソッドパブリック メソッド
( プロテクト メソッド参照)
  名前 説明
パブリック メソッド Clear Queue からすべてのオブジェクト削除します
パブリック メソッド Clone Queue簡易コピー作成します
パブリック メソッド Contains ある要素Queue 内に存在するかどうか判断します
パブリック メソッド CopyTo Queue要素既存1 次元Arrayコピーしますコピー操作は、配列内の指定したインデックスから始まります
パブリック メソッド Dequeue Queue先頭にあるオブジェクト削除し返します
パブリック メソッド Enqueue Queue末尾オブジェクト追加します
パブリック メソッド Equals  オーバーロードされます2 つObject インスタンス等しかどうか判断します。 (Object から継承されます。)
パブリック メソッド GetEnumerator Queue反復処理する列挙子を返します
パブリック メソッド GetHashCode  特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用適してます。 (Object から継承されます。)
パブリック メソッド GetType  現在のインスタンスType取得します。 (Object から継承されます。)
パブリック メソッド Peek Queue先頭にあるオブジェクト削除せず返します
パブリック メソッド ReferenceEquals  指定した複数Object インスタンス同一かどうか判断します。 (Object から継承されます。)
パブリック メソッド Synchronized 同期されている (スレッド セーフな) Queue ラッパー返します
パブリック メソッド ToArray Queue要素新し配列コピーします
パブリック メソッド ToString  現在の Object を表す String返します。 (Object から継承されます。)
パブリック メソッド TrimToSize 容量Queue 内にある実際要素数に設定します
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

Queue クラス
System.Collections 名前空間
System.Collections.Generic.Queue


このページでは「.NET Framework クラス ライブラリ リファレンス」からQueueを検索した結果を表示しています。
Weblioに収録されているすべての辞書からQueueを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からQueueを検索

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

辞書ショートカット

すべての辞書の索引

「Queue」の関連用語

Queueのお隣キーワード
検索ランキング

   

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



Queueのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2024 GRAS Group, Inc.RSS