Object Oriented Programming using C#

(backadmin) #1

Object Oriented Programming using C#
Generic Collections and how to Serialize them


Activity 4

Earlier we found that some of the useful methods for Lists included...

Add() – which adds an object onto the end of the list,
Clear() – which removes all the elements from the list,
Contains() – which returns true if this list contains the specified object,
Insert() – which inserts an element at the specified position,
Remove() - which removes the first occurrence of an object from a list and
Sort() – which sorts the element of the list.

Go online to msdn.microsoft.com. Find API for the HashSet class defined in the System.Collections.Generic namespace and
find out which of the methods in the List class have equivalent methods in the HashSet class.

Feedback 4

You should find Methods Add(), Clear() Contains() and Remove() methods also exist for a HashSet.

Insert() and Sort() do not exist. As sets are unsorted objects you cannot sort them and as they have no specific order it
make no sense to try to insert an object at a specified position.

There is much commonality between the different types of collection. Having learnt how to use one it is relatively easy to
learn another.
Free download pdf