Convert List<Cookie> to CookieCollection in C#

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);

Answers


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.


Given c and l as in your first example, this'll do:

l.ForEach(c.Add);

Need Your Help

How to set font of class names and methods in phpstorm

fonts phpstorm

I want to set font of class names and class methods as bold. Only for that two items in any language. But it seems that each language specific class names are inherited from "Identifier" item but not

Show chat logs history with asmack android

android chat smack asmack

Recently, I try to build a chat app in android with XMPP! I installed Ejabberd, and with connection, I can chat with another user with my android app! But now, I have an issue in retrieve chat logs

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.