Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 434145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:14:40+00:00 2026-05-12T20:14:40+00:00

In researching how to convert a NameValueCollection to a querystring, I have come across

  • 0

In researching how to convert a NameValueCollection to a querystring, I have come across different methods. I am curious if the shorter lambda syntax is as efficient as it could be.

How to convert NameValueCollection to a (Query) String using a iterating function.

public static String ConstructQueryString(NameValueCollection parameters)
{
    List<String> items = new List<String>();

    foreach (String name in parameters)
        items.Add(String.Concat(name, "=", System.Web.HttpUtility.UrlEncode(parameters[name])));

    return String.Join("&", items.ToArray());
}

Join a NameValueCollection into a querystring in C# uses a lambda expression, which looks nice but I’m not sure if it is efficient code.

private static string JoinNvcToQs(NameValueCollection qs)
{
    return string.Join("&", Array.ConvertAll(qs.AllKeys, key => string.Format("{0}={1}", HttpUtility.UrlEncode(key), HttpUtility.UrlEncode(qs[key]))));
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T20:14:40+00:00Added an answer on May 12, 2026 at 8:14 pm

    First of all, the best thing you can do is test and see if the performance is acceptable for your application, we can tell you generalities about performance but in the end it comes down to your needs and only you know the answers to that.

    As to the question at hand, any time you use a delegate (which is what a lambda creates) rather than executing the code directly you’ll take a performance hit. In most cases the hit is acceptable but if this code needs the absolute best possible performance (say it’s in an inner loop) then you need to go with your first method.

    That said, if you’re creating a querystring, presumably you’re about to hit the database which will likely take considerably longer than either method of creating the querystring in the first place.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been researching a few different apps lately for my company which are
While researching the issue of JSON vs XML , I came across this question
I have been researching asynchronous messaging, and I like the way it elegantly deals
I have been researching and playing with functional programming lately, solely to broaden my
I have been researching options for printing report-like data via a web application. Some
I have been Google-ing and researching for an answer on how to do a
I have encountered many different ways to turn a Java program into a Windows
I have so far been a dedicated Wordpress user, but have been researching other
I have been researching for a while and have actually created a prototype ASP.NET
I have been researching and have some few ideas about a distributed caching system

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.