C# Lists / Collections / Classes / Objects Flashcards
What is a list?
A list is similar to an array but provides additional functionality, such as dynamic resizing.
What is a collection?
The .NET Framework class library provides several classes, called collections, used to store groups of ralated objects. These classes provide efficient methods that organize, store and retrieve your data without requiring knowledge of how the data is being stored.
What is the generic collection class List?
The generic collection class List (from namespace System.Collections.Generic) does not need to be reallocated to change its size. List is called a generic class because it can be used with any type of object. T is a placeholder for the type of the objects stored in the list.
What are some common methods and properties of class List?
What does the count property do?
The count property returns the number of elements currently in the list
What does the capacity property do?
The capacity property indicates how many items the list can hold without having to grow
What are the capacity and count properties values when the list is initially created?
Both are initially 0, though the capacity is implementation dependent
How would you add items to the collection?
How does the elasticity of the capacity of a collection work?
What does the Add method do?
Appends its argument to the end of the list.
What does the insert method do?
inserts a new element at the specific position.
How would you index a list collection?
Lists can be indexed like arrays by placing the index in square brackets after the List variable’s name.
What does the remove method do?
the remove method is used to remove the first instance of an element with a specific value. If mp such element is in the list, remove does nothing.
What does the remove at method do?
It removes the element at the specified index; the indices of all elements above that index decrease by 1.
What does the contains method do?
The contains method returns true if the element is found in the list, and false otherwise.