How to Quickly Remove Items From a List

前端 未结 11 1569
情歌与酒
情歌与酒 2020-11-30 01:45

I am looking for a way to quickly remove items from a C# List. The documentation states that the List.Remove() and List.RemoveAt()<

11条回答
  •  我在风中等你
    2020-11-30 02:00

    The other answers (and the question itself) offer various ways of dealing with this "slug" (slowness bug) using the built-in .NET Framework classes.

    But if you're willing to switch to a third-party library, you can get better performance simply by changing the data structure, and leaving your code unchanged except for the list type.

    The Loyc Core libraries include two types that work the same way as List but can remove items faster:

    • DList is a simple data structure that gives you a 2x speedup over List when removing items from random locations
    • AList is a sophisticated data structure that gives you a large speedup over List when your lists are very long (but may be slower when the list is short).

提交回复
热议问题