Let’s say I have a Dictionary<String, Guid>
What is the fastest way to convert that to an ArrayList?
I can do the following:
ArrayList result = new ArrayList();
foreach (KeyValuePair<String, Guid> kvp in myDict) {
result.Add(new { Value = Base64Converter.ConvertBase64(kvp.Value), Display= kvp.Key});
}
But there has got to be a better way.
LINQ is your friend for compactly and expressively transforming collections:
In my experience LINQ to Objects is very well optimized for performance, but there is often a performance penalty compared to other options. For references see
http://blogs.msdn.com/b/csharpfaq/archive/2009/01/26/does-the-linq-to-objects-provider-have-built-in-performance-optimization.aspx
http://peterkellner.net/2009/06/03/linq-in-memory-performance/
http://you.arenot.me/2010/07/30/linq-to-objects-vs-list/
If you are interested in absolute performance over elegance, your method may turn out to be faster. However, unless your dictionary is quite large, it would be hard to measure the difference. If in doubt, benchmark.