Convert List<Cookie> to CookieCollection in C#
.net, c#, collections, list
Solution
CookieCollection was written before .Net 2 (before Generics). Therefore, there's really no quick nice way to do it other than manually with a foreach loop.
Problem
Let's say I have `List<Cookie>` and I want to convert it to a `CookieCollection`. What's the easiest way to do this? I know I can use a foreach loop, but isn't there a way to instantiate it with code similar to this? ``` List<Cookie> l = ...; var c = new CookieCollection() { l }; ``` When I try to compile that though, I get the error: The best overloaded Add method 'System.Net.CookieCollection.Add(System.Net.CookieCollection)' for the collection initializer has some invalid arguments btw, there are two `Add` methods that `CookieCollection` supports: ``` public void Add(Cookie cookie); public void Add(CookieCollection cookies); ```