【问题标题】:An Analog of List.h in .Net.Net 中 List.h 的模拟
【发布时间】:2010-01-16 10:07:45
【问题描述】:

我曾经使用 List.h 来处理 C++ 中的列表,但是 .Net 中是否有类似的库?因为我不能将 List.h 用于托管类型。

【问题讨论】:

  • 什么是 List.h?在 C++ 中,您应该使用 std::list 来处理列表
  • 您可能想了解更多有关 Linq-to-objects 和 System.Linq 命名空间的信息

标签: .net c++ list collections


【解决方案1】:

查看System.CollectionsSystem.Collections.Generic 命名空间。 在那里,您会找到 ArrayListList<T> 等类...

【讨论】:

    【解决方案2】:

    这里是一个使用 List 的例子:

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

    这里是 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;
    }
    

    【讨论】:

      【解决方案3】:

      System.Collections.Generic.LinkedList<T> 实现了相同的功能。

      【讨论】:

        【解决方案4】:

        如果您指的是 STL 列表,那么您将需要在 System.Collections.Generics 中找到的 LinkedList 泛型类

        .Net List 泛型类更像是一个 STL 向量

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2021-07-31
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2010-09-13
          相关资源
          最近更新 更多