Following roughly this answer, I want to get the first cookie with a certain name given an URI.
Uri uri = new Uri(url);
CookieContainer cookieJar = new CookieContainer();
...
CookieCollection cookies = cookieJar.GetCookies(uri);
Then, I can access the first (and at the moment the only) cookie like this.
Cookie cookie = cookies[0];
I see it's a collection and it has an enumerator. However, when I try to use LINQ, it seems that the collection isn't getting anything like this.
Cookie cookie = cookies
.First(c => c.Name == "vanilla");
The LINQ is imported at the top and it definitely works with a few test lines I threw in. There's no AsList()
or ToArray()
according to the intellisense, neither. The collection seems not to be very collection'ish.
What am I missing?
edit
I ended up copying over the contents like this. But it seems to clunky...
Cookie[] cookies = new Cookie[cookieJar.Count];
cookieJar.GetCookies(uri).CopyTo(cookies, 0);
Cookie cookie = cookies
.First(c => c.Name == "pm_retention_urls");