471,327 Members | 2,718 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,327 software developers and data experts.

Does 2005 C# have STL?

Does the 2005 release of Visual Studio provide either STL (the C++ Standard
Template Library) or an equivalent for C#? I am most interested in the 2005 C#
equivalent of std::vector.
Jan 16 '06 #1
6 2403
Peter Olcott <ol****@att.net> wrote:
Does the 2005 release of Visual Studio provide either STL (the C++ Standard
Template Library) or an equivalent for C#? I am most interested in the 2005 C#
equivalent of std::vector.


Look at System.Collections.Generic.List<T>
That's the closest equivalent, I believe.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 16 '06 #2
Peter,
Does the 2005 release of Visual Studio provide either STL (the C++
Standard Template Library) or an equivalent for C#? I am most interested
in the 2005 C# equivalent of std::vector.


In general, there are several classes in C# that provide the functionality
of std::vector. However, which to use depends on what storage model and
behavior you want to need. If you need fast lookup of random data in the
"vector", you might want to use:

System.Collections.Specialized.HybridDictionary

If your application needs a plain vanilla queue-like behavior, you might
start with:

System.Collections.Queue

If your application needs a plain vanilla array-like behavior where you
iterate over the elements, you might use:

System.Collections.ArrayList

If your application needs the list to be sorted, you might use:

System.Collections.SortedList

There are other collection, link-list, etc. classes, but I am sure you get
the idea. The one you pick depends on the characteristics that are most
important to the application. Start in the System.Collections namespace. I
hope that helps.

Regards,

Randy
Jan 16 '06 #3
Yeah, but, they all changed with 2005 to have generics too right?

"Randy A. Ynchausti" <ra*************@msn.com> wrote in message
news:OM**************@TK2MSFTNGP14.phx.gbl...
Peter,
Does the 2005 release of Visual Studio provide either STL (the C++ Standard
Template Library) or an equivalent for C#? I am most interested in the 2005
C# equivalent of std::vector.


In general, there are several classes in C# that provide the functionality of
std::vector. However, which to use depends on what storage model and behavior
you want to need. If you need fast lookup of random data in the "vector", you
might want to use:

System.Collections.Specialized.HybridDictionary

If your application needs a plain vanilla queue-like behavior, you might start
with:

System.Collections.Queue

If your application needs a plain vanilla array-like behavior where you
iterate over the elements, you might use:

System.Collections.ArrayList

If your application needs the list to be sorted, you might use:

System.Collections.SortedList

There are other collection, link-list, etc. classes, but I am sure you get the
idea. The one you pick depends on the characteristics that are most important
to the application. Start in the System.Collections namespace. I hope that
helps.

Regards,

Randy

Jan 16 '06 #4
On Mon, 16 Jan 2006 15:11:40 -0600, "Peter Olcott" <ol****@att.net>
wrote:
Does the 2005 release of Visual Studio provide either STL (the C++ Standard
Template Library) or an equivalent for C#? I am most interested in the 2005 C#
equivalent of std::vector.

VS 2005 is .NET 2.0 so it has generics. The closest to std::vector<t>
is System.Collections.Generics.List<T> which is contiguous storage,
random acces with an indexer ([]) and easy to add new items at the end
but not in the middle. THere are other containers in
System.Collections.Generics which you might want to look at as well,
depending on your exact requirements.

rossum

--

The ultimate truth is that there is no ultimate truth
Jan 16 '06 #5
Peter,
Yeah, but, they all changed with 2005 to have generics too right?


There is a new namespace, System.Collections.Generic. The Generics flavor
of the collection classes mainly provide a higher degree of type safety.
For example, let's say we want to have a dictionary that uses an integer as
the key and a DateTime as the value. The non-Generic version might be coded
as:

System.Collections.Specialized.HybridDictionary x = new
System.Collections.Specialized.HybridDictionary();
x.Add(1, DateTime.Now);
x.Add("Hello", "World"); // compiles and runs without errors

The non-generic version allows the wrong type of data to be added to the
collection at run-time. Also note that there are no compile-time issues.
The generics version won't allow you to even compile your application:

System.Collections.Generic.Dictionary<int, DateTime> y = new
System.Collections.Generic.Dictionary<int, DateTime>();
y.Add(1, DateTime.Now);
y.Add("Hello", "World"); // compiler error 1) can't convert string to int
and 2) can't convert string to DateTime

So one benefit of Generics is the type safety. However, there are simple
ways to guarantee type safety and use the non-generic incantations of the
collections.

Regards,

Randy
Jan 16 '06 #6
Randy A. Ynchausti <ra*************@msn.com> wrote:
Yeah, but, they all changed with 2005 to have generics too right?


There is a new namespace, System.Collections.Generic. The Generics flavor
of the collection classes mainly provide a higher degree of type safety.


Well, type-safety *and* performance. If you create an ArrayList and
call Add ((byte)10) to it a million times, you'll use up a *lot* more
memory than using List<byte>.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 17 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

54 posts views Thread by seberino | last post: by
14 posts views Thread by Anoop | last post: by
1 post views Thread by =?Utf-8?B?QmlsbHkgWmhhbmc=?= | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.