【问题标题】:How do i Dequeue a queue [closed]我如何使队列出队[关闭]
【发布时间】:2014-04-23 10:06:36
【问题描述】:

假设

Queue<String> aQueue =new Queue<string>();
Customer aCustomer=new Customer();

然后我将aCustomer 加入队列aCustomer。(几个值)

我怎样才能将aCustomer 去队列并将这些值放入aCustomer。(几个变量)。

如果有人有解决方案,请帮助我。

【问题讨论】:

  • 您能解释一下通过将属性值从对象推送到队列中来实现的目的吗?如果你解释你为什么这样做,你更有可能得到好的答案。

标签: c# queue


【解决方案1】:

您可以使用EnqueueDequeue

Queue<Customer> aQueue =new Queue<Customer>();
Customer aCustomer=new Customer();

aQueue.Enqueue(aCustomer);
aCustomer = aQueue.Dequeue();

【讨论】:

  • 很抱歉,但那是不可能的;
  • @user3245548:你能解释一下吗?
  • @PatrickHofman 为什么要更改aQueue 的类型?我认为这不是 OP 所需要的。
  • @Fyodor:因为否则它不会编译。我认为这就是OP想要的。这就是我要求 OP 澄清的原因。
  • 你不认为OP在他的Customer类型中真的有string类型的属性,他想把这个属性添加到aQueue中吗?我的意思是实际上还不清楚他在问什么。那么,如果问题不清楚,你怎么能假装回答呢?
【解决方案2】:

你在寻找这样的东西吗?

Queue<Customer> aQueue = new Queue<Customer>();
Customer customer = new Customer { Name = "Test" };
aQueue.Enqueue(customer);
customer = new Customer { Name = "Test1" };
aQueue.Enqueue(customer);
customer = new Customer { Name = "Test2" };
aQueue.Enqueue(customer);

while (aQueue.Any())
{
    customer = aQueue.Dequeue();
    // use customer
}

【讨论】:

    猜你喜欢
    • 2016-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-03
    • 1970-01-01
    • 1970-01-01
    • 2013-08-05
    • 2021-12-07
    相关资源
    最近更新 更多