This code should convert the list of listType2s (list) to a list of type1s. I feel the functionality is somewhat difficult to ascertain though.
I am looking to see alternative methods that are easier to read, yet concise, and brief.
List<Type1> type1s = new List<Type1>();
listType2s.ForEach(t => type1s.Add((new Type1(t))));
I generally agree with using LINQ for this sort of thing – but
List<T>has had aConvertAllmethod since .NET 2.0 which will actually be slightly more efficient (as it already knows the size):I would probably use LINQ myself unless I had a particular reason not to, just because then it’s consistent with the rest of the code which would probably be using LINQ too.