string.QueryString c#


  // Adding a second parameter with the same name (round 2).
  StringValues twoValues = StringValues.Concat(queryString["param2"], "my other value");
  parsedQueryString["coronavirus"] = twoValues;

  // Getting a param value
  var param2Value = queryString["param2"];
  // --> StringValues!

  param2Value.ToString(); // Get the values concatenated together
  param2Value.ToArray(); // Gets an array of strings

  // Modifying a parameter
  queryString["param1"] = "another value";
  // NOTE, if there were two values,
  // this overwrites both and leaves a single value.

  // Url Encoding the whole thing
  QueryString.Create(parsedQueryString).ToString();
  // --> "?param1=another%20value¶m2=my%20value¶m2=my%20other%20value

4.11
9
JuanTamad 70 points

                                    
 var queryString = QueryHelpers.ParseQuery("?param1=value");
  // queryString.GetType() --> typeof(Dictionary<String,StringValues>)

  // Adding a parameter
  queryString.Add("param2", "my value"); // Easy so far.

  // Adding a second parameter with the same name
  queryString.Add("param2", "my other value"); // ArgumentException!
  // --> An item with the same key has already been added

4.11 (9 Votes)
0
Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source