Collections in C#

  • Thread starter Thread starter Sandeep Limaye
  • Start date Start date
S

Sandeep Limaye

Hi,

I want to use collections (similar to maps in STL) in my C# code. I looked
up MSDN but they say that you need to inherit from the
System.Collections.Specialized.NameObjectCollectionBase class and also
implement a lot of methods (MSDN also gives sample code for the same). Is it
really required to do all that? Can I use the collection as simply as I can
use STL maps in C++?

Thanks,
Sandeep
 
You can use System.Collections.HashTable if you want something similiar to
STL maps. The only difference between HashTable and maps is that HashTable
is not type specialiazed (it's map where key and value is object type) .
Next version of .Net framework support specialized HashTable via generic
(something as c++ template).

Gianluca
 
There's a new feature coming in .NET framework 2.0 called "generics" which
will provide similar capabilities to templates in C++. Until then we're
stuck with System.Collections.

When using NameObjectCollectionBase you don't have to implement all the
methods - only the ones for the (type-strict) functionality you need.
 
imo STL doesn't exist in C#, because there is no need for it
due to the fact that C# is a truly object based language,
or alternatively, C++ needs STL because it isn't properly
object based.
 
Back
Top