SupermarketQueue.Serve C# (CSharp) Method

Serve() public method

public Serve ( int count ) : IEnumerable
count int
return IEnumerable
    public IEnumerable<string> Serve(int count)
    {
        if (count > this.peopleByPosition.Count || count < 0)
        {
            return null;
        }

        IList<string> toServe = new List<string>(this.peopleByPosition.Range(0, count));

        this.peopleByName.RemoveMany(toServe);
        this.peopleByPosition.RemoveRange(0, count);

        return toServe;
    }

Usage Example

    static void Main()
    {
        StringBuilder output = new StringBuilder();
        string commandLine = Console.ReadLine();
        SupermarketQueue supermarketQueue = new SupermarketQueue();
        while (commandLine != EndCommand)
        {
            string[] command = commandLine.Split(' ');
            switch (command[0])
            {
                case AppendCommand:
                    supermarketQueue.Append(command[1]);
                    output.AppendLine(OKMessage);
                    break;
                case InsertCommand:
                    if (supermarketQueue.Insert(int.Parse(command[1]), command[2]))
                    {
                        output.AppendLine(OKMessage);
                    }
                    else
                    {
                        output.AppendLine(ErrorMessage);
                    }

                    break;
                case FindCommnad:
                    output.AppendFormat("{0}{1}", supermarketQueue.Find(command[1]), Environment.NewLine);
                    break;
                case ServeCommand:
                    var served = supermarketQueue.Serve(int.Parse(command[1]));
                    if (served != null)
                    {
                        output.AppendLine(string.Join(" ", served));
                    }
                    else
                    {
                        output.AppendLine(ErrorMessage);
                    }

                    break;
            }

            commandLine = Console.ReadLine();
        }

        Console.Write(output);
    }
All Usage Examples Of SupermarketQueue::Serve