开发者

An Analog of List.h in .Net

I used to 开发者_如何学运维use List.h to work with lists in C++, but are there any similar libraries in .Net ? Becouse I can't use List.h for managed types.


Check out the System.Collections and System.Collections.Generic namespaces. There, you'll find classes like ArrayList, List<T>, etc...


Here is an example of using List:

List<string> myList = new List<string>();
myList.Add("Item1");
myList.Add("Item2");
myList.ForEach(s => Console.WriteLine(s.ToString()));

and here is an example of LinkedList:

LinkedList<int> myList = new LinkedList<int>();

myList.AddFirst(14);             
myList.AddLast(20);                            
myList.AddLast(34);             
myList.AddBefore(myList.Last, 65); 

LinkedListNode<int> myNode = myList.First;
while (myNode != null)
{
  Console.WriteLine(myNode.Value);
  myNode = myNode.Next;
}


System.Collections.Generic.LinkedList<T> achieves the same funcionality.


If you're referring to the STL list then you'll want the the LinkedList generic class found in System.Collections.Generics

The .Net List generic class is more like an STL vector

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜