c#中queue_C#中的Queue.Count属性示例

c#中queue

C#Queue.Count属性 (C# Queue.Count property)

Queue.Count property is used to get total number of elements of a Queue.

Queue.Count属性用于获取Queue的元素总数。

Syntax:

句法:

    int Queue.Clear;

Parameters: None

参数:

Return value: int – it returns total number of elements of a Queue.

返回值: int –返回队列中元素的总数。

Example:

例:

    declare and initialize a Queue:
    Queue que = new Queue();   

    insertting elements:
    que.Enqueue(100);
    que.Enqueue(200);
    que.Enqueue(300);
    que.Enqueue(400);
    que.Enqueue(500);
    
    printing length:
    que.Count;

    Output:
    5

C#示例使用Queue.Count属性获取队列的元素/对象总数 (C# example to get the total number of elements/objects of a Queue using Queue.Count property)

using System;
using System.Text;
using System.Collections;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            //declare and initialize a Queue
            Queue que = new Queue();

            //insertting elements
            que.Enqueue(100);
            que.Enqueue(200);
            que.Enqueue(300);
            que.Enqueue(400);
            que.Enqueue(500);

            //printing length
            Console.WriteLine("Total elements: " + que.Count);

            //declaring another Queue
            Queue que1 = new Queue();

            //printing length
            Console.WriteLine("Total elements: " + que1.Count);

            //hit ENTER to exit
            Console.ReadLine();
        }
    }
}

Output

输出量

Total elements: 5
Total elements: 0

Reference: Queue.Count Property

参考: Queue.Count属性

翻译自: https://www.includehelp.com/dot-net/queue-count-property-with-example-in-c-sharp.aspx

c#中queue

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值