How could I improve this C# randomising method?

前端 未结 7 2204
南方客
南方客 2021-02-10 20:30

I think I\'ve settled on this as the most simple and unit-testable method for randomising a list, but would be interested to hear of any improvements.

public sta         


        
7条回答
  •  梦毁少年i
    2021-02-10 20:48

    This looks good to me. Note that you'll get slightly better performance (especially for large lists) if you initialize ret with the length of list, so that the list doesn't have to be reallocated:

    List ret = new List(list.Count);
    

提交回复
热议问题