Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
The System.Collections Namespace3:24 with Jeremy McLain
The System.Collections namespace contains many other collections. Some of them are no longer used though.
Create a console application to keep track of things in your to-do list. Allow finding items in the list that are due on a given date or finished on a given date. Each item in the list should have the following fields:
- Due Date
- Date Finished
Create a console based version of the Memory board game. You can find the rules here. Use words for the cards. To make it slightly more complicated, you can allow the player to pick the grid size. Clear the screen between turns using Console.Clear().
Create a console application to keep track of contact information. Print the contacts of the address book in sorted order first by last name, then by first. For each person in the address book have fields for:
- First Name
- Last Name
- Phone Number
- Email Address
So far, we've only been working with collections in
the System.Collections.Generic namespace.
There are a couple of other namespaces that contain collection types that
you should be aware of.
These can all be found in the ParentSystem.Collections namespace.
I've included a link to a page that lists them in the teacher's notes.
The System.Collections.Object model namespace contains a number of
collections that are designed to be the base classes of other collection types.
When creating our own collection types,
it's often a good idea to start with one of these.
These are also generic classes that can work with any type of object.
Collections found in the System.Collections.Concurrent namespace
are used to share data between threads.
Computers can run code concurrently or
simultaneously with other code in a program.
This code is said to be running in separate threads.
The most difficult aspect of threaded programming is making sure that one thread
isn't unexpectedly changing the data that another thread is working with.
Concurrent programming is a topic for another day, but the collection types
provided here make threaded programming much easier and safer.
There are a number of collection types that are provided by
the System.Collections namespace itself.
They're listed here.
These are the original collection types provided by .Net before C#
had the capability of generic classes.
These non-generic collection types work with the base,
System.Object type that all other types inherit from.
This means, they can store any type of object.
However, we'd have to cast the object back to its actual type before we could use it.
This can be quite cumbersome.
Almost all of these collection types now have equivalents
in the System.Collections.Generic namespace.
The generic versions of these collections are easier to use and
are also more efficient.
These collections are now considered deprecated by most developers meaning,
they aren't used anymore.
They're still here for historical purposes though.
It's the same story with the collections
found in the System.Collections.Specialized namespace.
As the name suggests, these collections are more specialized and
less commonly used.
However, there are types of collections in here that don't have generic equivalents.
There are also a number of collection types in here that only work with strings,
but they're rarely used.
In general, it's always best to use a generic collection type.
Whoo, that about does it for collections provided by .NET.
There are many other useful collections that don't have implementations in .NET.
See the teachers notes for a list of some of these.
You may find that you wanna use a collection that isn't provided by
the .NET Framework.
In that case, you may be able to find third party libraries
that provide implementations of them.
Or you may want to implement your own collection type,
.NET makes it easy to extend existing types of collections or
combine them in unique and fascinating ways.
Using the right collection type for
what you want to do can greatly simplify your code and make it more efficient.
The more collections you know about,
the more likely you are to pick the right one for the job and use it correctly.
If you'd like to practice using some of the collections we've discussed here,
I've included a few project suggestions for you to implement on your own.
Until next time, happy coding.
You need to sign up for Treehouse in order to download course files.Sign up