Home > OS >  LINQ : how do I simplify this query?
LINQ : how do I simplify this query?

Time:05-11

How do I simplify this query?

var cookieList = _httpContextAccessor.HttpContext.Request.Cookies.ToList()
                .Select(cookie => new { cookie.Key, cookie.Value })
                .AsEnumerable()
                .Select(cookie => $"{cookie.Key}={cookie.Value}")
                .ToList()

CodePudding user response:

var cookieList = _httpContextAccessor.HttpContext.Request.Cookies // assumed IEnumerable otherwise .ToList is ok
                .Select(cookie => $"{cookie.Key}={cookie.Value}")
                .ToList()
  •  Tags:  
  • linq
  • Related