Ejemplo n.º 1
0
 public void Add(T item)
 {
     IgnoreNextCollectionChangedEvent = true;
     List.Add(item);
     FireAdd(item);
     NotifyCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, List.Count - 1));
 }
Ejemplo n.º 2
0
        public void ModifyCustomList(string[] inputArgs)
        {
            string command = inputArgs[0].ToLower();
            string element = string.Empty;
            int    index   = 0;

            switch (command)
            {
            case "add":
                element = inputArgs[1];
                customList.Add(element);
                break;

            case "remove":
                index = int.Parse(inputArgs[1]);
                customList.Remove(index);
                break;

            case "contains":
                element = inputArgs[1];
                bool isContains = customList.Contains(element);
                Console.WriteLine(isContains);
                break;

            case "swap":
                int firstIndex  = int.Parse(inputArgs[1]);
                int secondIndex = int.Parse(inputArgs[2]);
                customList.Swap(firstIndex, secondIndex);
                break;

            case "greater":
                element = inputArgs[1];
                int count = customList.CountGreaterThan(element);
                Console.WriteLine(count);
                break;

            case "max":
                string maxElement = customList.Max();
                Console.WriteLine(maxElement);
                break;

            case "min":
                string minElement = customList.Min();
                Console.WriteLine(minElement);
                break;

            case "print":
                Console.WriteLine(customList);
                break;

            default:
                throw new InvalidOperationException("Invalid command!");
            }
        }
Ejemplo n.º 3
0
        private static void Main(string[] args)
        {
            CustomListClass cl = new CustomListClass();

            ICustomList list = cl as ICustomList;

            Console.WriteLine("Add 3 elements");

            list.Add(25);
            list.Add(26);
            list.Add(27);

            Console.WriteLine("The sum is " + list.Sum);

            Console.WriteLine("Set 0-th element");

            list.At[0] = 28;

            Console.WriteLine("The sum is " + list.Sum);

            Console.WriteLine("Iterate");

            Console.WriteLine("The size is " + list.Count);

            for (uint i = 0; i < list.Count; i++)
            {
                Console.WriteLine("\tItem at position " + i + " is " + list.At[i]);
            }

            Console.WriteLine("Remove 3 elements");

            list.Remove(28);
            list.Remove(26);
            list.Remove(27);

            Console.WriteLine("The size is " + list.Count);
            Console.WriteLine("The sum is " + list.Sum);
        }
Ejemplo n.º 4
0
    private static void ExecuteCommand(ICustomList <string> customList, string command)
    {
        var commandArgs = command.Split(' ');
        var commandName = commandArgs[0];
        var args        = commandArgs.Skip(1).ToArray();

        switch (commandName)
        {
        case "Add":
            customList.Add(args[0]);
            break;

        case "Remove":
            customList.Remove(int.Parse(args[0]));
            break;

        case "Contains":
            Console.WriteLine(customList.Contains(args[0]));
            break;

        case "Swap":
            customList.Swap(int.Parse(args[0]), int.Parse(args[1]));
            break;

        case "Greater":
            Console.WriteLine(customList.CountGreaterThan(args[0]));
            break;

        case "Max":
            Console.WriteLine(customList.Max());
            break;

        case "Min":
            Console.WriteLine(customList.Min());
            break;

        case "Print":
            Console.WriteLine(customList);
            break;

        case "Sort":
            customList.Sort();
            break;

        default:
            break;
        }
    }
Ejemplo n.º 5
0
    private static void Execute(string command, ICustomList <string> myList)
    {
        var commandArgs = command.Split();

        switch (commandArgs[0])
        {
        case "Add":
            myList.Add(commandArgs[1]);
            break;

        case "Remove":
            myList.Remove(int.Parse(commandArgs[1]));
            break;

        case "Contains":
            Console.WriteLine(myList.Contains(commandArgs[1]));
            break;

        case "Swap":
            myList.Swap(int.Parse(commandArgs[1]), int.Parse(commandArgs[2]));
            break;

        case "Greater":
            Console.WriteLine(myList.CountGreaterThan(commandArgs[1]));
            break;

        case "Min":
            Console.WriteLine(myList.Min());
            break;

        case "Max":
            Console.WriteLine(myList.Max());
            break;

        case "Print":
            Console.WriteLine(string.Join(Environment.NewLine, myList));
            break;

        case "Sort":
            myList.Sort();
            break;

        default:
            break;
        }
    }
Ejemplo n.º 6
0
 public override void Execute(string[] inputParameters, ICustomList <string> listOfItems)
 {
     listOfItems.Add(inputParameters[1]);
 }
 public void AddChild(PersistentObjectBaseWithNameHierarchical<T> child)
 {
     if (ChildList.Count() != 0)
         child.OrderPosition = ChildList.Max(e => e.OrderPosition) + 1;
     ChildList.Add(child);
 }