SupermarketQueue.Insert C# (CSharp) Method

Insert() public method

public Insert ( int position, string name ) : bool
position int
name string
return bool
    public bool Insert(int position, string name)
    {
        if (position > this.peopleByPosition.Count || position < 0)
        {
            return false;
        }

        this.peopleByName.Add(name);
        this.peopleByPosition.Insert(position, name);

        return true;
    }
}

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::Insert