skynyrd
9/7/2016 - 8:06 AM

Optimization for C# code

Optimization for C# code

Optimization Notes

1. For huge lists, create list of defined size, or low level array.
var list = new List<Foo>(99999999);
var arr = new Foo[99999999];
2. Do not use IndexOf() as it searches the item index using algorithm with O(n) complexity
3. Assume there is a huge listSource IList.

INSTEAD OF THIS:

var listToBeCreated = new List<Foo>();

listSource.ToList().ForEach(item => listToBeCreated.Add(new Foo(item.bar, item.tar, item.zar)))

USE THIS:

var listToBeCreated = listSource.Select(item => new Foo(item.bar, item.tar, item.zar));