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

While researching how to create custom compound views in Android, I have come across
I've been researching how to successfully convert C++ pointer-to-member to C# but I haven't
After researching a bit how the different way people slugify titles, I've noticed that
After some time researching and trying different things I still cannot get my @ExceptionHandler
I have been researching for over an hour and finding great samples of how
I have to convert a long string of data into values so that I
In researching how iOS devices (iPhone/iPad/iPodTouch) are protected via encrypted I came across many
After researching my options with regards to video support in Java, I stumbled across
I have a quick question for you all. I'm trying to convert over some
I'm trying to convert site www.mircscripts.org to Drupal, and researching more and more about

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.