public static void ListExampleGenerics(IGenericList <string> listOfGenerics) { listOfGenerics.Add("a"); // [a] listOfGenerics.Add("b"); // [a,b] listOfGenerics.Add("car"); // [a,b,car] listOfGenerics.Add("house"); // [a,b,car,house] listOfGenerics.Add("roof"); // [a,b,car,house,roof] listOfGenerics.RemoveAt(0); // [b,car,house,roof] listOfGenerics.Remove("house"); //[b,car,house] Console.WriteLine(listOfGenerics.Count); // 3 Console.WriteLine(listOfGenerics.Remove("nonExistingWord")); // false Console.WriteLine(listOfGenerics.RemoveAt(5)); // false listOfGenerics.Clear(); // [] Console.WriteLine(listOfGenerics.Count); // 0 }
public static void ListExample(IGenericList <int> listOfIntegers) { listOfIntegers.Add(1); // [1] listOfIntegers.Add(2); // [1 ,2] listOfIntegers.Add(3); // [1 ,2 ,3] listOfIntegers.Add(4); // [1 ,2 ,3 ,4] listOfIntegers.Add(5); // [1 ,2 ,3 ,4 ,5] listOfIntegers.RemoveAt(0); // [2 ,3 ,4 ,5] listOfIntegers.Remove(5); //[2 ,3 ,4] Console.WriteLine(listOfIntegers.Count); // 3 Console.WriteLine(listOfIntegers.Remove(100)); // false Console.WriteLine(listOfIntegers.RemoveAt(5)); // false listOfIntegers.Clear(); // [] Console.WriteLine(listOfIntegers.Count); // 0 }
public static void ListExample(IGenericList <string> list) { list.Add("1a"); list.Add("2b"); list.Add("3c"); list.Add("4d"); list.Add("5e"); list.RemoveAt(0); list.Remove("5e"); WriteLine(list.GetElement(2)); WriteLine(list.Count); WriteLine(list.Remove("100")); WriteLine(list.RemoveAt(5)); list.Clear(); WriteLine(list.Count); }
public static void ListOfExamples(IGenericList <double> listOfIntegers) { listOfIntegers.Add(1.3); // [1] listOfIntegers.Add(2.2); // [1 ,2] listOfIntegers.Add(3.4); // [1 ,2 ,3] listOfIntegers.Add(4.5); // [1 ,2 ,3 ,4] listOfIntegers.Add(5.2); // [1 ,2 ,3 ,4 ,5] listOfIntegers.RemoveAt(0); // [2 ,3 ,4 ,5] listOfIntegers.Remove(5.2); Console.WriteLine(listOfIntegers.Count); // 3 Console.WriteLine(listOfIntegers.Remove(100)); // false Console.WriteLine(listOfIntegers.RemoveAt(5)); // false listOfIntegers.Clear(); // [] Console.WriteLine(listOfIntegers.Count); // 0 Console.ReadLine(); }
/// <summary> /// Changes a ToDoItem inside collection, unless it does not exist. Then it adds given item. /// Perhaps not an ideal solution, wait for next patch... /// </summary> /// <param name="todoItem"></param> public void Update(TodoItem toDoItem) { if (Get(toDoItem.Id) != null) { _inMemoryToDoDatabase.RemoveAt(_inMemoryToDoDatabase.IndexOf(toDoItem)); } Add(toDoItem); }
public void ListExample(IGenericList <float> list) { list.Add(2); list.Add(3); Console.WriteLine(list); list.Add(4); list.Add(5); list.RemoveAt(0); Console.WriteLine(list); Console.WriteLine(list.Count); Console.ReadLine(); }
public TodoItem Update(TodoItem todoItem) { int index = _inMemoryTodoDatabase.IndexOf(todoItem); TodoItem a = _inMemoryTodoDatabase.GetElement(index); if (_inMemoryTodoDatabase.Contains(todoItem)) { a = todoItem; _inMemoryTodoDatabase.RemoveAt(index); } _inMemoryTodoDatabase.Add(a); return(todoItem); }
public bool Remove(Guid todoId) { /// <summary > /// Tries to remove a TodoItem with given id from the database . /// </ summary > /// <returns > True if success , false otherwise </ returns > TodoItem temp = _inMemoryTodoDatabase.Where(o => o.Id.Equals(todoId)).FirstOrDefault(); if (temp != null) { //int index = _inMemoryTodoDatabase.IndexOf(temp); return(_inMemoryTodoDatabase.RemoveAt(_inMemoryTodoDatabase.IndexOf(temp))); } return(false); //throw new NotImplementedException(); }
private IGenericList<ICard> ShuffleList(IGenericList<ICard> inputList) { var randomList = new GenericList<ICard>(); Random r = new Random(); int randomIndex = 0; while (inputList.Count > 0) { randomIndex = r.Next(0, inputList.Count); //Choose a random object in the list randomList.Add(inputList[randomIndex]); //add it to the new, random list inputList.RemoveAt(randomIndex); //remove to avoid duplicates } return randomList; //return the new random list }