How to Create a Thread-Safe Generic List?

后端 未结 8 1175
借酒劲吻你
借酒劲吻你 2020-12-08 10:42

I have a Generic List as below

public static readonly List Customers = new List();

I\'m using the below met

相关标签:
8条回答
  • 2020-12-08 11:21

    Never use ConcurrangBag for ordered data. Use Array instead

    0 讨论(0)
  • 2020-12-08 11:24

    Use the lock keyword when you manipulate the collection, ie: your Add/Find:

    lock(Customers) {
        Customers.Add(new Customer());
    }
    
    0 讨论(0)
提交回复
热议问题