Esta propiedad se utiliza para obtener el número de elementos contenidos en la Cola. Recuperar el valor de esta propiedad es una operación O(1) y se incluye en el espacio de nombres System.Collections .
Sintaxis:
public virtual int Count { get; }
Valor de la propiedad: esta propiedad devuelve el número de elementos contenidos en la cola.
Los siguientes programas ilustran el uso de la propiedad discutida anteriormente:
Ejemplo 1:
// C# code to illustrate the // Queue.Count Property using System; using System.Collections; class GFG { // Driver code public static void Main() { // Creating a Queue Queue myQueue = new Queue(); // Displaying the count of elements // contained in the Queue Console.Write("Total number of elements"+ " in the Queue are : "); // The function should return 0 // as the Queue is empty and it // doesn't contain any element Console.WriteLine(myQueue.Count); } }
Producción:
Total number of elements in the Queue are : 0
Ejemplo 2:
// C# code to illustrate the // Queue.Count Property using System; using System.Collections; class GFG { // Driver code public static void Main() { // Creating a Queue Queue myQueue = new Queue(); // Inserting the elements into the Queue myQueue.Enqueue("C"); myQueue.Enqueue("C++"); myQueue.Enqueue("Java"); myQueue.Enqueue("C#"); myQueue.Enqueue("HTML"); myQueue.Enqueue("CSS"); // Displaying the count of elements // contained in the Queue Console.Write("Total number of elements "+ "in the Queue are : "); Console.WriteLine(myQueue.Count); } }
Producción:
Total number of elements in the Queue are : 6
Referencia:
Publicación traducida automáticamente
Artículo escrito por Kirti_Mangal y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA