.NET Collections
-
Hi, I've been looking over the Collection classes available through the .NET framework and it seems that LinkedList hasn't been provided (Unless it is in some other namespace which I haven't checked - If so could you point it out - Thanks!). Any ideas as to why they haven't included it in the Framework? It is a very useful data structure and has many uses just as ArrayList does. Actually... it would be a good article to compare the Collections framework that .NET and Java provide. Cause I know that the Java Collections framework is heavily based on inheritance and abstract classes. It would be an interesting article to see the differences between them. As a side question - Are the .NET Enumerators the same as the Java Iterators? Thanks very much. Mohnish
-
Hi, I've been looking over the Collection classes available through the .NET framework and it seems that LinkedList hasn't been provided (Unless it is in some other namespace which I haven't checked - If so could you point it out - Thanks!). Any ideas as to why they haven't included it in the Framework? It is a very useful data structure and has many uses just as ArrayList does. Actually... it would be a good article to compare the Collections framework that .NET and Java provide. Cause I know that the Java Collections framework is heavily based on inheritance and abstract classes. It would be an interesting article to see the differences between them. As a side question - Are the .NET Enumerators the same as the Java Iterators? Thanks very much. Mohnish
mohn3310 wrote: Any ideas as to why they haven't included it in the Framework? Good question, it does seem odd that it isn't there. You could easily create your own version of it though. If you don't know how to create a linked list there are many places on the web that will give you code for doing it :) mohn3310 wrote: Are the .NET Enumerators the same as the Java Iterators? Enumerators in .NET are used to go through a collection an element at a time.
IEnumerator ie = myCollection.GetEnumerator();
while(ie.MoveNext) {
System.Console.WriteLine("object: " + ie.Current.ToString());
}or if you are using C# you can use foreach
foreach(object foo in myCollection) {
System.Console.WriteLine("object: " + foo.ToString();
}Simple, eh? :) HTH, James Sonork ID: 100.11138 - Hasaki "Smile your little smile, take some tea with me awhile. And every day we'll turn another page. Behind our glass we'll sit and look at our ever-open book, One brown mouse sitting in a cage." "One Brown Mouse" from Heavy Horses, Jethro Tull 1978
-
mohn3310 wrote: Any ideas as to why they haven't included it in the Framework? Good question, it does seem odd that it isn't there. You could easily create your own version of it though. If you don't know how to create a linked list there are many places on the web that will give you code for doing it :) mohn3310 wrote: Are the .NET Enumerators the same as the Java Iterators? Enumerators in .NET are used to go through a collection an element at a time.
IEnumerator ie = myCollection.GetEnumerator();
while(ie.MoveNext) {
System.Console.WriteLine("object: " + ie.Current.ToString());
}or if you are using C# you can use foreach
foreach(object foo in myCollection) {
System.Console.WriteLine("object: " + foo.ToString();
}Simple, eh? :) HTH, James Sonork ID: 100.11138 - Hasaki "Smile your little smile, take some tea with me awhile. And every day we'll turn another page. Behind our glass we'll sit and look at our ever-open book, One brown mouse sitting in a cage." "One Brown Mouse" from Heavy Horses, Jethro Tull 1978
Thanks James! Yes, LinkedLists are relatively simple to create and there are lots of examples on the web, but I was just wondering why they didn't include it since it's such a generic data structure. Normally we would create wrappers to ArrayLists or LinkedLists to make them typesafe (using our own classes) rather than using Objects. Yeah, enumerators do seem to act like iterators in java. Cool... thnx again Mohnish
-
Thanks James! Yes, LinkedLists are relatively simple to create and there are lots of examples on the web, but I was just wondering why they didn't include it since it's such a generic data structure. Normally we would create wrappers to ArrayLists or LinkedLists to make them typesafe (using our own classes) rather than using Objects. Yeah, enumerators do seem to act like iterators in java. Cool... thnx again Mohnish
mohn3310 wrote: Normally we would create wrappers to ArrayLists or LinkedLists to make them typesafe (using our own classes) rather than using Objects. Microsoft has made that part easier on us developers :) Collection Generator for .NET 1.0 creates a collection based on ArrayLists to store objects of a specified type. Until .NET supports generics this is the best solution to it. James Sonork ID: 100.11138 - Hasaki "Smile your little smile, take some tea with me awhile. And every day we'll turn another page. Behind our glass we'll sit and look at our ever-open book, One brown mouse sitting in a cage." "One Brown Mouse" from Heavy Horses, Jethro Tull 1978